Function glommio::timer::timeout [−][src]
pub async fn timeout<F, T>(dur: Duration, f: F) -> Result<T, ()> where
F: Future<Output = Result<T, ()>>,
Expand description
Executes a future with a specified timeout
Returns a Result
, with Ok
if the future ran to completion
or a GlommioError::TimedOut
error if the timeout was reached
timeout(Duration::from_millis(1), async move {
// this future will wait for 100ms, but won't complete, as the timeout is 1ms
Timer::new(Duration::from_millis(100)).await;
Ok(())
})
.await;