Trait tokio_util::time::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 Future
s.
Provided Methods§
sourcefn timeout(self, timeout: Duration) -> Timeout<Self>where
Self: Sized,
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());