Skip to main content

channel

Function channel 

Source
pub fn channel<T>(buffer: usize) -> (Sender<T>, Receiver<T>)
Expand description

Creates a bounded channel that holds at most buffer messages, and answers its two halves.

The halves belong to the tasks of one shard: they are !Send. A send on a full channel waits in line for room.

ยงPanics

When buffer is zero, or more than Semaphore::MAX_PERMITS.

use nuclei::sync::local::mpsc;

let (tx, mut rx) = mpsc::channel(2);
tx.try_send(1).unwrap();
tx.try_send(2).unwrap();
assert!(tx.try_send(3).is_err());
assert_eq!(rx.try_recv(), Ok(1));