[][src]Function kayrx_timer::throttle

pub fn throttle<T>(duration: Duration, stream: T) -> Throttle<T> where
    T: Stream

Slow down a stream by enforcing a delay between items. They will be produced not more often than the specified interval.

Example

Create a throttled stream.

use std::time::Duration;
use futures_util::stream::StreamExt;
use kayrx_timer::throttle;

let mut item_stream = throttle(Duration::from_secs(2), futures::stream::repeat("one"));

loop {
    // The string will be produced at most every 2 seconds
    println!("{:?}", item_stream.next().await);
}