Function blinkcast::alloc::channel

source ·
pub fn channel<T: Clone>(size: usize) -> (Sender<T>, Receiver<T>)
Expand description

Creates a new channel, returning the Sender and Receiver for it.

Both of the sender and receiver are cloneable, so you can have multiple senders and receivers.

Another method to create a channel is using the Sender::new and Sender::new_receiver methods.

Examples

use blinkcast::alloc::channel;
let (sender, mut receiver) = channel::<i32>(4);

sender.send(1);
sender.send(2);

assert_eq!(receiver.recv(), Some(1));

let sender2 = sender.clone();
sender2.send(3);

assert_eq!(receiver.recv(), Some(2));

let mut receiver2 = receiver.clone();
assert_eq!(receiver.recv(), Some(3));
assert_eq!(receiver2.recv(), Some(3));
assert_eq!(receiver.recv(), None);
assert_eq!(receiver2.recv(), None);