Function darkfi::system::timeout::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 using io_timeout instead.


use std::time::Duration;
use smol::future;

let never = future::pending::<()>();
let dur = Duration::from_millis(5);
assert!(timeout(dur, never).await.is_err());