Crate shared_channel
source ·Expand description
Multi-producer, multi-consumer FIFO queue communication primitives.
This module is extension of std::sync::mpsc
, almost has same API
with it.
Differences are:
- A struct
SharedReceiver
is defined. This is clone-able struct (multi-consumer). - A function
shared_channel
corresponding to functionchannel
is defined.shared_channel
returns a(Sender, SharedReceiver)
tuple instead of(Sender, Receiver)
tuple. - Some feature of
std::sync::mpsc
is not implemented yet.
Example
Simple usage:
let (tx, rx) = shared_channel();
for i in 0..10 {
let rx = rx.clone();
thread::spawn(move || println!("{}", rx.recv().unwrap()));
}
for i in 0..10 {
tx.send(i).unwrap();
}
More examples, see examples directory.