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