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> { ... }
}
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)
.
§Limitations
This uses SleepProvider::sleep
for its timer, and is
subject to the same limitations.
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.
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.
This uses SleepProvider::sleep
for its timer, and is
subject to the same limitations.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.