pub trait SleepProviderExt: SleepProvider {
// Provided methods
fn timeout<F: Future>(
&self,
duration: Duration,
future: F,
) -> Timeout<F, Self::SleepFuture> ⓘ { ... }
fn sleep_until_wallclock(
&self,
when: SystemTime,
) -> SleepUntilWallclock<'_, Self> ⓘ { ... }
fn sleep_until(&self, deadline: Instant) -> Self::SleepFuture { ... }
}Expand description
An extension trait on SleepProvider for timeouts and clock delays.
Provided Methods§
Sourcefn timeout<F: Future>(
&self,
duration: Duration,
future: F,
) -> Timeout<F, Self::SleepFuture> ⓘ
fn timeout<F: Future>( &self, duration: Duration, future: F, ) -> Timeout<F, Self::SleepFuture> ⓘ
Wrap a Future with a timeout.
The output of the new future will be the returned value of
future if it completes within duration. Otherwise, it
will be Err(TimeoutError).
This uses SleepProvider::sleep for its timer.
Sourcefn sleep_until_wallclock(
&self,
when: SystemTime,
) -> SleepUntilWallclock<'_, Self> ⓘ
fn sleep_until_wallclock( &self, when: SystemTime, ) -> SleepUntilWallclock<'_, Self> ⓘ
Pause until the wall-clock is at when or later, trying to
recover from clock jumps.
This uses SleepProvider::sleep for its timer.
Unlike SleepProvider::sleep(), the future returned by this function will
wake up periodically to check the current time, and see if
it is at or past the target.
§Limitations
The ability of this function to detect clock jumps is limited to its granularity; it may finish a while after the declared wallclock time if the system clock jumps forward.
This function does not detect backward clock jumps; arguably, we should have another function to do that.
Sourcefn sleep_until(&self, deadline: Instant) -> Self::SleepFuture
fn sleep_until(&self, deadline: Instant) -> Self::SleepFuture
Return a future that will be ready when deadline is reached.
This uses SleepProvider::sleep for its timer.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".