[−][src]Function flume::bounded
pub fn bounded<T>(cap: usize) -> (Sender<T>, Receiver<T>)
Create a channel with a maximum capacity.
Create a bounded channel with a Sender and Receiver connected to each end
respectively. Values sent in one end of the channel will be received on the other end. The
channel is thread-safe, and both sender and receiver may be sent to threads as necessary. In
addition, Sender may be cloned.
Unlike an unbounded channel, if there is no space left for new messages, calls to
Sender::send will block (unblocking once a receiver has made space). If blocking behaviour
is not desired, Sender::try_send may be used.
Like std::sync::mpsc, flume supports 'rendezvous' channels. A bounded queue with a maximum
capacity of zero will block senders until a receiver is available to take the value.
Examples
let (tx, rx) = flume::bounded(32); for i in 1..33 { tx.send(i).unwrap(); } assert!(tx.try_send(33).is_err()); assert_eq!(rx.try_iter().sum::<u32>(), (1..33).sum());