macro_rules! merge_futures {
($($fut:expr),+ $(,)?) => { ... };
}Expand description
Poll the futures concurrently and return their outputs as a stream.
Produces a stream that yields N values, where N is the number of merged futures. The
outputs will be returned in the order in which the futures completed.
§Minimal polling
This stream will only poll each inner future when it is awoken, rather than polling all inner futures on each iteration.
§Pinning
The input futures to this macro must be pinned to the local context via pin.
§Examples
use std::time::Duration;
use std::pin::pin;
use futures_lite::StreamExt;
use local_runtime::time::sleep;
use local_runtime::merge_futures;
let a = pin!(async { 1 });
let b = pin!(async {
sleep(Duration::from_millis(5)).await;
2
});
let c = pin!(async {
sleep(Duration::from_millis(3)).await;
3
});
let mut stream = merge_futures!(a, b, c);
while let Some(x) = stream.next().await {
// Expect the values to be: 1, 3, 5
println!("Future returned: {x}");
}