pub fn join<Fut>(
futures: impl IntoIterator<Item = Fut>,
concurrency: usize,
) -> LimitedJoin<Fut> ⓘwhere
Fut: Future,Expand description
Returns a future that acts as a join of multiple futures, but with a limit on how many futures can be running at once.
§Example
use std::time::{Duration, Instant};
use tokio::time::sleep;
let then = Instant::now();
let futures = std::iter::repeat(Duration::from_millis(100))
.map(|duration| async move { sleep(duration).await })
.take(4);
limited_join::join(futures, 2).await;
// Ensure all futures completed in roughly 200ms as we're processing only 2 at a time.
assert!(then.elapsed().as_millis() - 200 < 10);