pub trait SleepProvider:
Clone
+ Send
+ Sync
+ 'static {
type SleepFuture: Future<Output = ()> + Send + 'static;
// Required method
fn sleep(&self, duration: Duration) -> Self::SleepFuture;
// Provided methods
fn now(&self) -> Instant { ... }
fn wallclock(&self) -> SystemTime { ... }
fn block_advance<T: Into<String>>(&self, _reason: T) { ... }
fn release_advance<T: Into<String>>(&self, _reason: T) { ... }
fn allow_one_advance(&self, _dur: Duration) { ... }
}
Expand description
Trait for a runtime that can wait until a timer has expired.
Every SleepProvider
also implements
SleepProviderExt
; see that trait
for other useful functions.
Required Associated Types§
Sourcetype SleepFuture: Future<Output = ()> + Send + 'static
type SleepFuture: Future<Output = ()> + Send + 'static
A future returned by SleepProvider::sleep()
Required Methods§
Sourcefn sleep(&self, duration: Duration) -> Self::SleepFuture
fn sleep(&self, duration: Duration) -> Self::SleepFuture
Return a future that will be ready after duration
has
elapsed.
Provided Methods§
Sourcefn now(&self) -> Instant
fn now(&self) -> Instant
Return the SleepProvider’s view of the current instant.
(This is the same as Instant::now
, if not running in test mode.)
Sourcefn wallclock(&self) -> SystemTime
fn wallclock(&self) -> SystemTime
Return the SleepProvider’s view of the current wall-clock time.
(This is the same as SystemTime::now
, if not running in test mode.)
Sourcefn block_advance<T: Into<String>>(&self, _reason: T)
fn block_advance<T: Into<String>>(&self, _reason: T)
Signify that a test running under mock time shouldn’t advance time yet, with a given unique reason string. This is useful for making sure (mock) time doesn’t advance while things that might require some (real-world) time to complete do so, such as spawning a task on another thread.
Call release_advance
with the same reason string in order to unblock.
This method is only for testing: it should never have any effect when invoked on non-testing runtimes.
Sourcefn release_advance<T: Into<String>>(&self, _reason: T)
fn release_advance<T: Into<String>>(&self, _reason: T)
Signify that the reason to withhold time advancing provided in a call to block_advance
no
longer exists, and it’s fine to move time forward if nothing else is blocking advances.
This method is only for testing: it should never have any effect when invoked on non-testing runtimes.
Sourcefn allow_one_advance(&self, _dur: Duration)
fn allow_one_advance(&self, _dur: Duration)
Allow a test running under mock time to advance time by the provided duration, even if the
above block_advance
API has been used.
This method is only for testing: it should never have any effect when invoked on non-testing runtimes.
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.
Implementations on Foreign Types§
Source§impl SleepProvider for AsyncStd
Available on (crate features native-tls
or rustls
) and (crate features async-std
or tokio
) and crate feature async-std
only.
impl SleepProvider for AsyncStd
native-tls
or rustls
) and (crate features async-std
or tokio
) and crate feature async-std
only.Implementors§
Source§impl SleepProvider for AsyncStdNativeTlsRuntime
Available on (crate features native-tls
or rustls
) and crate feature async-std
only.
impl SleepProvider for AsyncStdNativeTlsRuntime
native-tls
or rustls
) and crate feature async-std
only.Source§impl SleepProvider for AsyncStdRustlsRuntime
Available on (crate features native-tls
or rustls
) and crate feature async-std
only.
impl SleepProvider for AsyncStdRustlsRuntime
native-tls
or rustls
) and crate feature async-std
only.Source§impl SleepProvider for TokioRuntimeHandle
Available on (crate features native-tls
or rustls
) and (crate features async-std
or tokio
) and crate feature tokio
only.
impl SleepProvider for TokioRuntimeHandle
native-tls
or rustls
) and (crate features async-std
or tokio
) and crate feature tokio
only.type SleepFuture = Sleep
Source§impl SleepProvider for DynTimeProvider
impl SleepProvider for DynTimeProvider
Source§impl SleepProvider for PreferredRuntime
impl SleepProvider for PreferredRuntime
type SleepFuture = <TokioNativeTlsRuntime as SleepProvider>::SleepFuture
Source§impl SleepProvider for TokioNativeTlsRuntime
Available on (crate features native-tls
or rustls
) and crate feature tokio
only.
impl SleepProvider for TokioNativeTlsRuntime
native-tls
or rustls
) and crate feature tokio
only.Source§impl SleepProvider for TokioRustlsRuntime
Available on (crate features native-tls
or rustls
) and crate feature tokio
only.
impl SleepProvider for TokioRustlsRuntime
native-tls
or rustls
) and crate feature tokio
only.