Function async_std::channel::unbounded

source ·
pub fn unbounded<T>() -> (Sender<T>, Receiver<T>)
Expand description

Creates an unbounded channel.

The created channel can hold an unlimited number of messages.

Examples

use async_channel::{unbounded, TryRecvError};

let (s, r) = unbounded();

assert_eq!(s.send(10).await, Ok(()));
assert_eq!(s.send(20).await, Ok(()));

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