expression
Bound concurrent future processing
Limit the number of futures polled concurrently in a stream pipeline. Completion order may differ from input order, so sort results when order is not meaningful. This limit does not bound all allocations or external resource consumption. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): [2, 4, 6] Common mistake: Using an unbounded collection of spawned tasks instead of bounded concurrency.
Formal Syntax & Structure
rust syntaxrust
StreamExt::buffer_unordered(limit)Working Example
Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() { use futures_util::{stream, StreamExt}; let mut out: Vec<_> = stream::iter([3, 1, 2]) .map(|n| async move { n * 2 }) .buffer_unordered(2).collect().await; out.sort_unstable(); println!("{out:?}");}