merge_streams

Macro merge_streams 

Source
macro_rules! merge_streams {
    ($($fut:expr),+ $(,)?) => { ... };
}
Expand description

Run the streams concurrently and return their outputs one at a time.

Produces a stream that yields the outputs of the inner streams as they become available, effectively interleaving the inner streams.

§Minimal polling

This stream will only poll each inner stream when it is awoken, rather than polling all inner streams on each iteration.

§Pinning

The input streams to this macro must be pinned to the local context via pin.

§Examples

use std::time::Duration;
use std::pin::pin;
use futures_lite::{Stream, StreamExt};
use local_runtime::time::Periodic;
use local_runtime::merge_streams;

let a = pin!(Periodic::periodic(Duration::from_millis(70)).map(|_| 1u8));
let b = pin!(Periodic::periodic(Duration::from_millis(30)).map(|_| 2u8));
let stream = merge_streams!(a, b);
assert_eq!(stream.take(6).collect::<Vec<_>>().await, &[2, 2, 1, 2, 2, 1]);