timeout in async_std::future - Rust (original) (raw)

logo

async_std1.13.2

Sections

In async_std::future

async_std::future

Function timeout

Source

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 usingio::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());