[][src]Trait runtime::time::StreamExt

pub trait StreamExt: Stream + Sized + Unpin {
    fn timeout(self, dur: Duration) -> TimeoutStream<Self> { ... }

Extend Stream with methods to time out execution.

Provided methods

fn timeout(self, dur: Duration) -> TimeoutStream<Self>

Creates a new stream which will take at most dur time to yield each item of the stream.

This combinator creates a new stream which wraps the receiving stream in a timeout-per-item. The stream returned will resolve in at most dur time for each item yielded from the stream. The first item's timer starts when this method is called.

If a stream's item completes before dur elapses then the timer will be reset for the next item. If the timeout elapses, however, then an error will be yielded on the stream and the timer will be reset.


use runtime::time::{Interval, StreamExt as _};
use std::time::{Duration, Instant};

let start = Instant::now();
let mut interval = Interval::new(Duration::from_millis(10))
while let Some(now) = interval.next().await {
    println!("{}ms have elapsed", (now? - start).as_millis());

assert!(Instant::now() - start >= Duration::from_millis(30));
Loading content...


impl<S: Stream + Unpin> StreamExt for S[src]

fn timeout(self, dur: Duration) -> TimeoutStream<Self>[src]

Loading content...