[−][src]Trait smol_timeout::TimeoutExt
Provided methods
fn timeout(self, after: Duration) -> Timeout<Self>ⓘ where
Self: Sized,
Self: Sized,
Given a Duration
, creates and returns a new Timeout
that will poll both the future
and a Timer
that will complete after the provided duration, and return the future's
output or None
if the timer completes first.
Example
use async_io::Timer; use smol_timeout::TimeoutExt; use std::time::Duration; let foo = async { Timer::after(Duration::from_millis(250)).await; 24 }; let foo = foo.timeout(Duration::from_millis(100)); assert_eq!(foo.await, None); let bar = async { Timer::after(Duration::from_millis(100)).await; 42 }; let bar = bar.timeout(Duration::from_millis(250)); assert_eq!(bar.await, Some(42));