Expand description
§SPMC
A single producer, multiple consumers. Commonly used to implement work-stealing.
§Example
let (mut tx, rx) = spmc::channel();
let mut handles = Vec::new();
for n in 0..5 {
let rx = rx.clone();
handles.push(thread::spawn(move || {
let msg = rx.recv().unwrap();
println!("worker {} recvd: {}", n, msg);
}));
}
for i in 0..5 {
tx.send(i * 2).unwrap();
}
for handle in handles {
handle.join().unwrap();
}
Structs§
- Receiver
- The receiving side of a SPMC channel.
- Recv
Error - An error returned from the
recv
function on aReceiver
. - Send
Error - An error returned from the
Sender::send
orSyncSender::send
function on channels. - Sender
- The Sending side of a SPMC channel.
Enums§
- TryRecv
Error - This enumeration is the list of the possible reasons that
try_recv
could not return data when called. This can occur with both achannel
and async_channel
.
Functions§
- channel
- Create a new SPMC channel.