Function doublecross::bounded[][src]

pub fn bounded<T, U>(cap: usize) -> (BiChannel<T, U>, BiChannel<U, T>)

Creates a bi-directional channel of bounded capacity.

This type of channel has an internal buffer of length cap in which messages get queued; the buffer for each side of the channel is distinct.

A rather special case is a zero-capacity channel, also known as a rendezvous channel. Such a channel cannot hold any messages since its buffer is of length zero. Instead, send and receive operations must be executing at the same time in order to pair up and pass the message over.

Type Arguments

Unforunately it is often necessary to annotate types to help the compiler; the type T refers to the type the left channel receives and the right channel sends, and the type U inversely refers to the type the right channel receives and the left channel sends.

Warning

No effort is made to prevent a deadlock (ie both sides waiting for a buffer space on the other side) and it is important to use this channel in such a way as to avoid deadlocks, or to recognize their occurence and handle them.

Examples

let (left, right) = bounded::<(), ()>(0);

thread::spawn(move || {
    // ...
    left.send(());
});

println!("waiting for rendezvous");
right.recv().unwrap();
println!("rendezvous complete");