Function async_channel::bounded[][src]

pub fn bounded<T>(cap: usize) -> (Sender<T>, Receiver<T>)

Creates a bounded channel.

The created channel has space to hold at most cap messages at a time.

Panics

Capacity must be a positive number. If cap is zero, this function will panic.

Examples

use async_channel::{bounded, TryRecvError, TrySendError};

let (s, r) = bounded(1);

assert_eq!(s.send(10).await, Ok(()));
assert_eq!(s.try_send(20), Err(TrySendError::Full(20)));

assert_eq!(r.recv().await, Ok(10));
assert_eq!(r.try_recv(), Err(TryRecvError::Empty));