futures_ratelimit/
lib.rs

1//! Rate-limited version of `FuturesUnordered`/`FuturesOrdered`
2//!
3//! This crate provides a rate-limited version of `FuturesUnordered`/`FuturesOrdered`.
4//!
5//! The default `FuturesUnordered` does not provide any means to limit how many
6//! futures are polled at any given time. While you can use semaphores or any other
7//! forms of resource locking, that won't stop the async runtime from potentially
8//! polling (and thus, wasting CPU) too many futures at once. You can use channels, but
9//! that feels cumbersome and means extra code and added overhead.
10//!
11//! This crate provides types that behave just like the usual `futures`-(un)ordered types,
12//! except that you can specify a maximum number of futures that can be polled at any
13//! given time. This allows you to create and _submit_ tons of futures without
14//! overwhelming the async runtime.
15//!
16//! The logic is rather simple: we override the underlying' `poll_next()`,
17//! and, when necessary, pop a new future from either an iterator or a queue (at your
18//! choice). This means that we'll always be running **exactly** N futures (or less, if
19//! the futures source has been exhausted).
20//!
21//! The wrapped types have been designed such that the checks (to pop for more futures)
22//! are executed only when needed, thus making everything as efficient as it gets.
23//!
24//! Make sure to check out the docs for examples!
25pub mod common;
26pub mod ordered;
27pub mod unordered;