Function par_stream::gather [−][src]
pub fn gather<S>(
buf_size: impl Into<Option<usize>>,
streams: impl IntoIterator<Item = S>
) -> Gather<S::Item> where
S: 'static + StreamExt + Unpin + Send,
S::Item: Send,
Expand description
Collect multiple streams into single stream.
use futures::stream::StreamExt;
use par_stream::ParStreamExt;
use std::collections::HashSet;
async fn main_async() {
let orig = futures::stream::iter(0..1000);
// scatter stream items to two receivers
let rx1 = orig.scatter(None);
let rx2 = rx1.clone();
// gather back from two receivers
let values: HashSet<_> = par_stream::gather(None, vec![rx1, rx2]).collect().await;
// the gathered values have equal content with the original
assert_eq!(values, (0..1000).collect::<HashSet<_>>());
}