async_fifo/channel/
mod.rs

1//! Channels based on [`crate::fifo`]
2//!
3//! # Example
4//!
5//! ```rust
6//! # use async_fifo::{block_on, Closed};
7//! # block_on(async {
8//! let (tx, mut rx) = async_fifo::new();
9//! tx.send_iter(['a', 'b', 'c']);
10//!
11//! // Receive one by one
12//! assert_eq!(rx.recv().await, Ok('a'));
13//! assert_eq!(rx.recv().await, Ok('b'));
14//! assert_eq!(rx.recv().await, Ok('c'));
15//!
16//! core::mem::drop(tx);
17//! assert_eq!(rx.recv().await, Err(Closed));
18//! # });
19//! ```
20
21use crate::fifo::DefaultBlockSize;
22
23pub mod non_blocking;
24mod subscription;
25mod async_api;
26mod future;
27
28pub use async_api::*;
29pub use future::*;
30
31#[doc(inline)]
32pub use oneshot::new as oneshot;
33
34#[cfg(feature = "blocking")]
35mod blocking;
36
37#[cfg(feature = "async-read")]
38mod async_read;
39
40pub mod oneshot;
41
42/// Creates a channel with the default block size
43pub fn new<T: 'static>() -> (Sender<T>, Receiver<T>) {
44    DefaultBlockSize::channel()
45}