merge-streams

Crates.iomerge-streams
lib.rsmerge-streams
version0.1.2
sourcesrc
created_at2022-02-24 13:15:34.635216
updated_at2022-03-01 12:25:11.346138
descriptionMerge multiple streams into one
homepage
repositoryhttps://github.com/phil-opp/merge-streams
max_upload_size
id538510
size43,210
Philipp Oppermann (phil-opp)

documentation

https://docs.rs/merge-streams

README

merge-streams

Merge multiple streams into one.

Based on Yoshua Wuyts's futures-concurrency crate and the corresponding Futures Concurrency III post. Since the futures-concurrency crate now supports stable Rust too, there is no reason to this crate instead anymore.

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);
    })
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 47

cargo fmt