1 2 3 4 5 6 7 8 9 10
use futures::future::Future; use std::time::Duration; pub use tokio::time::error::Elapsed as TimeoutError; pub async fn timeout<F, T>(dur: Duration, f: F) -> Result<T, TimeoutError> where F: Future<Output = T>, { tokio::time::timeout(dur, f).await }