Crate stream_throttle
source ·Expand description
Provides a
Stream
combinator, to limit the rate at which
items are produced.
Key Features
- 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.
Example throttling of Stream
let rate = ThrottleRate::new(5, Duration::new(2, 0));
let pool = ThrottlePool::new(rate);
let work = stream::repeat(())
.throttle(pool)
.for_each(|_| Ok(()));
tokio::run(work);
Example throttling of Future
let rate = ThrottleRate::new(5, Duration::new(2, 0));
let pool = ThrottlePool::new(rate);
let work = pool.queue()
.then(|_| Ok(()));
tokio::run(work);
Modules
Structs
A clonable object which is used to throttle one or more streams, according to a shared rate.
Defines the the throttle rate.
A stream combinator which throttles its elements via a shared
ThrottlePool
.Traits
Provides a
throttle()
method on all Stream
’s.