pub fn bounded<T>(capacity: usize) -> (RSender<T>, RReceiver<T>)
Available on crate feature channels only.
Expand description

Creates a channel which can hold up to capacity elements in its internal queue.

If capacity==0,the value must be sent to a receiver in the middle of a recv call.

Panics

Panics if capacity >= usize::max_value() / 4.

Example

use abi_stable::external_types::crossbeam_channel as mpmc;

let (tx, rx) = mpmc::bounded::<u32>(3);

std::thread::spawn(move || {
    tx.send(10).unwrap();
    tx.send(11).unwrap();
    tx.send(12).unwrap();
});

assert_eq!(rx.recv().unwrap(), 10);
assert_eq!(rx.recv().unwrap(), 11);
assert_eq!(rx.recv().unwrap(), 12);
assert!(rx.try_recv().is_err());