futures_concurrency/stream/
mod.rs

1//! Composable asynchronous iteration.
2//!
3//! # Examples
4//!
5//! Merge multiple streams to handle values as soon as they're ready, without
6//! ever dropping a single value:
7//!
8//! ```
9//! use futures_concurrency::prelude::*;
10//! use futures_lite::stream::{self, StreamExt};
11//! use futures_lite::future::block_on;
12//!
13//! block_on(async {
14//!     let a = stream::once(1);
15//!     let b = stream::once(2);
16//!     let c = stream::once(3);
17//!     let s = (a, b, c).merge();
18//!
19//!     let mut counter = 0;
20//!     s.for_each(|n| counter += n).await;
21//!     assert_eq!(counter, 6);
22//! })
23//! ```
24//!
25//! # Concurrency
26//!
27//! When working with multiple (async) iterators, the ordering in which
28//! iterators are awaited is important. As part of async iterators, Rust
29//! provides built-in operations to control the order of execution of sets of
30//! iterators:
31//!
32//! - `merge`: combine multiple iterators into a single iterator, where the new
33//!   iterator yields an item as soon as one is available from one of the
34//!   underlying iterators.
35//! - `zip`: combine multiple iterators into an iterator of pairs. The
36//!   underlying iterators will be awaited concurrently.
37//! - `chain`: iterate over multiple iterators in sequence. The next iterator in
38//!   the sequence won't start until the previous iterator has finished.
39//!
40//! ## Futures
41//!
42//! Futures can be thought of as async sequences of single items. Using
43//! `stream::once`, futures can be converted into async iterators and then used
44//! with any of the iterator concurrency methods. This enables operations such
45//! as `stream::Merge` to be used to execute sets of futures concurrently, but
46//! obtain the individual future's outputs as soon as they're available.
47//!
48//! See the [future concurrency][crate::future#concurrency] documentation for
49//! more on futures concurrency.
50pub use chain::Chain;
51pub use into_stream::IntoStream;
52pub use merge::Merge;
53pub use stream_ext::StreamExt;
54#[doc(inline)]
55#[cfg(feature = "alloc")]
56pub use stream_group::StreamGroup;
57pub use wait_until::WaitUntil;
58pub use zip::Zip;
59
60/// A growable group of streams which act as a single unit.
61#[cfg(feature = "alloc")]
62pub mod stream_group;
63
64pub(crate) mod chain;
65mod into_stream;
66pub(crate) mod merge;
67mod stream_ext;
68pub(crate) mod wait_until;
69pub(crate) mod zip;