Provides a
Rust
Stream
combinator, to limit the rate at which items are produced.
- Throttling is implemented via
poll()
, and not via any sort of buffering. - The throttling behaviour can be applied to both
Stream
's andFuture
's. - Multiple streams/futures can be throttled together as a group.
let rate = ThrottleRate::new(5, Duration::new(1, 0));
let pool = ThrottlePool::new(rate);
let work = stream::repeat(())
.throttle(pool)
.for_each(|_| Ok(()));
tokio::run(work);
let rate = ThrottleRate::new(5, Duration::new(1, 0));
let pool = ThrottlePool::new(rate);
let work = pool.queue()
.then(|_| Ok(()));
tokio::run(work);