You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
I want one thread to read stick events, another one to pick up the latest read event and send it off on a network socket. For networking purposes I'm using tokio, not pasts crate.
The issue is, I can't spawn a task with tokio as Controller has an Rc inside and rust is unhappy about it not being Send.
Here's the gist of the code:
letmut state = State::new(...);letmut controller = get_ctl().await;
tokio::spawn(asyncmove{// => error here => future created by async block is not `Send`loop{let event = (&mut controller).await;// => also error => has type `Controller` which is not `Send`
state.event(event);}});
(Please forgive any stupid usage of rust / tokio / stick / async, I'm a newbie to both rust and async!)
Can you please guide me on how to achieve this? how should I send a controller through an async task? does this require fundamental changes to stick to use Arc?
The text was updated successfully, but these errors were encountered:
I cloned the repo and by turning Rc in stick::Controller into Arc, I still had to implement Send manually to make rust happy. I'm definitely doing something wrong here.
@hkoosha Thanks for opening this issue! I just put together #46 which should do the work to make the futures Send (apparently a common issue people are running into with my crates, so good to fix). Luckily this change wasn't too much work, let me know if it works or if you have any questions about what I did.
Once a type is !Send, you can't fix that by wrapping it in another type because it still breaks the promise of it being !Send if you are moving the type to another thread. So there are two possible solutions: a) have a thread own that type and communicate via a channel, b) make the type Send - if you can prove it unsafe impl Send {}, otherwise it can be automatically inferred (in this change I just added it as a requirement of the trait, and needed to replace occurrences of Rc with Arc).
Hi!
I want one thread to read stick events, another one to pick up the latest read event and send it off on a network socket. For networking purposes I'm using tokio, not pasts crate.
The issue is, I can't spawn a task with tokio as
Controller
has anRc
inside and rust is unhappy about it not beingSend
.Here's the gist of the code:
(Please forgive any stupid usage of rust / tokio / stick / async, I'm a newbie to both rust and async!)
Can you please guide me on how to achieve this? how should I send a controller through an async task? does this require fundamental changes to
stick
to useArc
?The text was updated successfully, but these errors were encountered: