Implement throttle combinator (#736)

Throttle down a stream by enforcing a fixed delay between items.
This commit is contained in:
Moritz Gunz
2018-11-19 15:04:55 -08:00
committed by Carl Lerche
parent b7506cf663
commit e166c4d912
4 changed files with 243 additions and 1 deletions
+12 -1
View File
@@ -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`.
///