pub async fn timeout<F, T>(dur: Duration, f: F) -> Result<T, TimeoutError>where
F: Future<Output = T>,
Expand description
Awaits a future or times out after a duration of time.
If you want to await an I/O future consider using
io::timeout
instead.
§Examples
use std::time::Duration;
use async_std::future;
let never = future::pending::<()>();
let dur = Duration::from_millis(5);
assert!(future::timeout(dur, never).await.is_err());