mitsuhiko / tokio-unix-ipc

A super minimal wrapper around unix sockets for IPC on top of tokio.
Apache License 2.0
43 stars 10 forks source link

Cannot use Bootstrapper in a tokio task. #2

Closed conorbros closed 2 years ago

conorbros commented 3 years ago

If I try to do the code snippet below, to have a background task wait for a message over IPC I get a compiler error:

`Cell<isize>` cannot be shared between threads safely

Is there any reason the sender field of Bootstrapper can't be changed from a RefCell to an Arc which would make this possible? Or is there a different way to go about what I am trying to achieve?

tokio::spawn(async move {
        let bootstrapper = {
            let bootstrapper = tokio_unix_ipc::Bootstrapper::bind("/tmp/test-uds").unwrap();
            bootstrapper.send(Message::Sender(tx)).await.unwrap();
            bootstrapper
        };

        tokio::select! {
            res = rx.recv() => {
                if let Ok(msg) = res {
                    match msg {
                        _ => {}
                    }
                }
            }
        };
});
conorbros commented 3 years ago

Example in this repo: https://github.com/conorbros/tokio-unix-ipc

mitsuhiko commented 2 years ago

Duplicate of #13