Function par_stream::par_gather[][src]

pub fn par_gather<S>(
    streams: impl IntoIterator<Item = S>,
    buf_size: impl Into<Option<usize>>
) -> ParGather<S::Item> where
    S: 'static + StreamExt + Unpin + Send,
    S::Item: Send

Collect multiple streams into single stream.

use futures::stream::StreamExt;
use par_stream::ParStreamExt;
use std::collections::HashSet;

async fn main() {
    let outer = Box::new(2);

    // scatter to two receivers
    let (scatter_fut, rx1) = futures::stream::iter(0..1000).par_scatter(None);
    let rx2 = rx1.clone();

    // gather back from two receivers
    let gather_fut = par_stream::par_gather(vec![rx1, rx2], None).collect::<HashSet<_>>();

    // collect the items from respective workers
    let ((), values) = futures::join!(scatter_fut, gather_fut);

    // the gathered values have exactly the same size with the stream
    assert_eq!(values, (0..1000).collect::<HashSet<_>>());
}