[−][src]Trait runtime::time::AsyncReadExt
Extend AsyncRead
with methods to time out execution.
Provided methods
fn timeout(self, dur: Duration) -> TimeoutAsyncRead<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.
Examples
use futures::prelude::*; use runtime::prelude::*; use runtime::net::TcpStream; use std::time::{Duration, Instant}; let start = Instant::now(); let stream = TcpStream::connect("127.0.0.1:8080").await?; let _stream = stream.timeout(Duration::from_millis(100));