mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-26 00:00:16 +02:00
Implement throttle combinator (#736)
Throttle down a stream by enforcing a fixed delay between items.
This commit is contained in:
+12
-1
@@ -1,4 +1,7 @@
|
||||
use tokio_timer::Timeout;
|
||||
use tokio_timer::{
|
||||
throttle::Throttle,
|
||||
Timeout,
|
||||
};
|
||||
|
||||
use futures::Stream;
|
||||
|
||||
@@ -19,6 +22,14 @@ use std::time::Duration;
|
||||
///
|
||||
/// [`timeout`]: #method.timeout
|
||||
pub trait StreamExt: Stream {
|
||||
/// Throttle down the stream by enforcing a fixed delay between items.
|
||||
///
|
||||
/// Errors are also delayed.
|
||||
fn throttle(self, duration: Duration) -> Throttle<Self>
|
||||
where Self: Sized
|
||||
{
|
||||
Throttle::new(self, duration)
|
||||
}
|
||||
|
||||
/// Creates a new stream which allows `self` until `timeout`.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user