futures_concurrency/stream/merge/
mod.rs

1use futures_core::Stream;
2
3pub(crate) mod array;
4pub(crate) mod tuple;
5#[cfg(feature = "alloc")]
6pub(crate) mod vec;
7
8/// Combines multiple streams into a single stream of all their outputs.
9///
10/// Items are yielded as soon as they're received, and the stream continues
11/// yield until both streams have been exhausted. The output ordering
12/// between streams is not guaranteed.
13///
14/// # Examples
15///
16/// ```
17/// use futures_concurrency::prelude::*;
18/// use futures_lite::stream::{self, StreamExt};
19/// use futures_lite::future::block_on;
20///
21/// block_on(async {
22///     let a = stream::once(1);
23///     let b = stream::once(2);
24///     let c = stream::once(3);
25///     let mut s = [a, b, c].merge();
26///
27///     let mut buf = vec![];
28///     s.for_each(|n| buf.push(n)).await;
29///     buf.sort_unstable();
30///     assert_eq!(&buf, &[1, 2, 3]);
31/// })
32/// ```
33pub trait Merge {
34    /// The resulting output type.
35    type Item;
36
37    /// The stream type.
38    type Stream: Stream<Item = Self::Item>;
39
40    /// Combine multiple streams into a single stream.
41    fn merge(self) -> Self::Stream;
42}