3 ms·
You probably want channels. There's an implementation in the standard library: https://doc.rust-lang.org/std/sync/mpsc/ https://doc.rust-lang.org/std/sync/mpsc
by nicoburns 7y ago
You probably want channels.
There's an implementation in the standard library: https://doc.rust-lang.org/std/sync/mpsc/ https://doc.rust-lang.org/std/sync/mpsc/
Or a faster/more ergonomic one in the crossbeam-channel library: https://docs.rs/crossbeam-channel/0.4.0/crossbeam_channel/ https://docs.rs/crossbeam-channel/0.4.0/crossbeam_channel/
- asdkhadsj 7y agoI've used them a ton in Go, and a tiny bit in Rust. I would think channels could fail here though - for the same reason that a Mutex could fail, no? Channels can block a thread if you wait for data. You could of course have a channel that you simply use in a non-blocking fashion, asking if data is ready. You could also implement similar behavior in a Mutex. However, I do think you're right, a channel would likely fit this paradigm better; and with less chance of accidentally blocking the executor/future thread. Appreciate the feedback, thanks!