Expand description
Merge multiple streams into one.
Based on Yoshua Wuyts’s
futures-concurrency
crate and the corresponding
Futures Concurrency III
post.
The main trait of this crate is MergeStreams
, which provides a merge
function on tuples, arrays, and vectors of streams. The StreamExt
trait provides a Stream::merge
method to make merging two streams more
convenient.
§Example
Merge multiple streams to handle values as soon as they’re ready, without ever dropping a single value:
use merge_streams::MergeStreams;
use futures_lite::future::block_on;
use futures_lite::{stream, StreamExt};
fn main() {
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 counter = 0;
s.for_each(|n| counter += n).await;
assert_eq!(counter, 6);
})
}
Traits§
- Into
Stream - Helper trait for converting values into a
Stream
. - Merge
Streams - Combines multiple streams into a single stream of all their outputs.
- Stream
Ext - Extend
Stream
with amerge
method.