stream_throttle

Provides a Rust Stream combinator, to limit the rate at which items are produced.

Crates.io API Documentation

Key Features

Feature Flags

If you don't use the default timer (tokio), make sure to set default-features = false in your Cargo.toml, when you add stream_throttle as a dependency.

Example throttling of Stream

```rust // allow no more than 5 items every 1 second let rate = ThrottleRate::new(5, Duration::new(1, 0)); let pool = ThrottlePool::new(rate);

let work = stream::repeat(()) .throttle(pool) .then(|| futures::future::ready("do something else")) .foreach(|_| futures::future::ready(()));

work.await; ```

Example throttling of Future

```rust let rate = ThrottleRate::new(5, Duration::new(1, 0)); let pool = ThrottlePool::new(rate);

let work = pool.queue() .then(|_| futures::future::ready("do something else"));

work.await; ```