rskit-stream 0.2.0-alpha.2

Foundational async stream toolkit: bounded fan-out broadcaster, sources, cancellable tasks, and futures::Stream extension operators
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use futures::StreamExt;

/// Merge two streams, yielding items from whichever is ready first.
pub fn merge<T: Send + 'static>(
    s1: impl futures::Stream<Item = T> + Send + 'static,
    s2: impl futures::Stream<Item = T> + Send + 'static,
) -> impl futures::Stream<Item = T> + Send + 'static {
    futures::stream::select(s1, s2)
}

/// Concatenate a list of streams — exhausts each before moving to the next.
pub fn concat<T: Send + 'static>(
    streams: Vec<impl futures::Stream<Item = T> + Send + 'static>,
) -> impl futures::Stream<Item = T> + Send + 'static {
    futures::stream::iter(streams).flatten()
}