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.Sender
is a struct that defined atstd::sync::mpsc
. - A function
shared_sync_channel
corresponding to functionsync_channel
is also defined. - Some feature of
std::sync::mpsc
is not implemented yet, for examplerecv_timeout
.
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.
Structs
The clone-able
td::sync::mpsc::Receiver
.