Crates.io | stream_throttle |
lib.rs | stream_throttle |
version | 0.5.1 |
source | src |
created_at | 2018-05-27 15:43:46.408644 |
updated_at | 2023-09-05 22:25:21.769582 |
description | Provides a Stream combinator, to limit the rate at which items are produced. |
homepage | |
repository | https://github.com/mikecaines/stream-throttle |
max_upload_size | |
id | 67292 |
size | 45,091 |
Provides a
Rust
Stream
combinator, to limit the rate at which items are produced.
poll()
,
and not via any sort of buffering.Stream
's and Future
's.timer-tokio
: Uses the tokio::time::delay_for()
timer.timer-futures-timer
: Uses the futures_timer::Delay
timer.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.
Stream
// 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"))
.for_each(|_| futures::future::ready(()));
work.await;
Future
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;