tokio_util::time

Trait FutureExt

Source
pub trait FutureExt: Future {
    // Provided method
    fn timeout(self, timeout: Duration) -> Timeout<Self>
       where Self: Sized { ... }
}
Available on crate feature time only.
Expand description

A trait which contains a variety of convenient adapters and utilities for Futures.

Provided Methods§

Source

fn timeout(self, timeout: Duration) -> Timeout<Self>
where Self: Sized,

A wrapper around tokio::time::timeout, with the advantage that it is easier to write fluent call chains.

§Examples
use tokio::{sync::oneshot, time::Duration};
use tokio_util::time::FutureExt;

let (tx, rx) = oneshot::channel::<()>();

let res = rx.timeout(Duration::from_millis(10)).await;
assert!(res.is_err());

Implementors§

Source§

impl<T: Future + ?Sized> FutureExt for T