Trait SleepProvider

pub(crate) 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>(&self, _reason: T)
       where T: Into<String> { ... }
    fn release_advance<T>(&self, _reason: T)
       where T: Into<String> { ... }
    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§

type SleepFuture: Future<Output = ()> + Send + 'static

A future returned by SleepProvider::sleep()

Required Methods§

fn sleep(&self, duration: Duration) -> Self::SleepFuture

Return a future that will be ready after duration has elapsed.

Provided Methods§

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.)

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.)

fn block_advance<T>(&self, _reason: T)
where T: Into<String>,

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.

fn release_advance<T>(&self, _reason: T)
where T: Into<String>,

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.

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 MockRuntime

Source§

impl SleepProvider for SimpleMockTimeProvider

Source§

impl SleepProvider for MockSleepProvider

Source§

type SleepFuture = Sleeping

Source§

fn sleep( &self, duration: Duration, ) -> <MockSleepProvider as SleepProvider>::SleepFuture

Source§

fn block_advance<T>(&self, reason: T)
where T: Into<String>,

Source§

fn release_advance<T>(&self, reason: T)
where T: Into<String>,

Source§

fn allow_one_advance(&self, dur: Duration)

Source§

fn now(&self) -> Instant

Source§

fn wallclock(&self) -> SystemTime

§

impl SleepProvider for AsyncStd

§

type SleepFuture = Pin<Box<dyn Future<Output = ()> + Send>>

§

fn sleep(&self, duration: Duration) -> <AsyncStd as SleepProvider>::SleepFuture

Source§

impl<R> SleepProvider for MockNetRuntime<R>
where R: Runtime,

Source§

type SleepFuture = <R as SleepProvider>::SleepFuture

Source§

fn sleep( &self, dur: Duration, ) -> <MockNetRuntime<R> as SleepProvider>::SleepFuture

Source§

fn now(&self) -> Instant

Source§

fn wallclock(&self) -> SystemTime

Source§

fn block_advance<T>(&self, reason: T)
where T: Into<String>,

Source§

fn release_advance<T>(&self, reason: T)
where T: Into<String>,

Source§

fn allow_one_advance(&self, dur: Duration)

Source§

impl<R> SleepProvider for MockSleepRuntime<R>
where R: Runtime,

Implementors§

§

impl SleepProvider for AsyncStdNativeTlsRuntime

§

type SleepFuture = <CompoundRuntime<AsyncStd, AsyncStd, RealCoarseTimeProvider, AsyncStd, AsyncStd, NativeTlsProvider, AsyncStd> as SleepProvider>::SleepFuture

§

impl SleepProvider for AsyncStdRustlsRuntime

§

type SleepFuture = <CompoundRuntime<AsyncStd, AsyncStd, RealCoarseTimeProvider, AsyncStd, AsyncStd, RustlsProvider, AsyncStd> as SleepProvider>::SleepFuture

§

impl SleepProvider for DynTimeProvider

§

type SleepFuture = Pin<Box<dyn Future<Output = ()> + Send>>

§

impl SleepProvider for PreferredRuntime

§

type SleepFuture = <TokioNativeTlsRuntime as SleepProvider>::SleepFuture

§

impl SleepProvider for TokioNativeTlsRuntime

§

type SleepFuture = <CompoundRuntime<TokioRuntimeHandle, TokioRuntimeHandle, RealCoarseTimeProvider, TokioRuntimeHandle, TokioRuntimeHandle, NativeTlsProvider, TokioRuntimeHandle> as SleepProvider>::SleepFuture

§

impl SleepProvider for TokioRustlsRuntime

§

type SleepFuture = <CompoundRuntime<TokioRuntimeHandle, TokioRuntimeHandle, RealCoarseTimeProvider, TokioRuntimeHandle, TokioRuntimeHandle, RustlsProvider, TokioRuntimeHandle> as SleepProvider>::SleepFuture

§

impl<TaskR, SleepR, CoarseTimeR, TcpR, UnixR, TlsR, UdpR> SleepProvider for CompoundRuntime<TaskR, SleepR, CoarseTimeR, TcpR, UnixR, TlsR, UdpR>
where SleepR: SleepProvider, TaskR: Clone + Send + Sync + 'static, CoarseTimeR: Clone + Send + Sync + 'static, TcpR: Clone + Send + Sync + 'static, UnixR: Clone + Send + Sync + 'static, TlsR: Clone + Send + Sync + 'static, UdpR: Clone + Send + Sync + 'static,