SleepProvider

Trait SleepProvider 

Source
pub trait SleepProvider {
    type Sleep: Future<Output = ()> + Send;

    // Required method
    fn sleep_for(dur: Duration) -> Self::Sleep;
}
Available on crate feature futures only.
Expand description

A trait that abstracts over how to sleep for a given Duration in async contexts.

This allows the generator to be generic over runtimes like Tokio or Smol.

Required Associated Types§

Source

type Sleep: Future<Output = ()> + Send

We require Send so that the future can be safely moved across threads

Required Methods§

Source

fn sleep_for(dur: Duration) -> Self::Sleep

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.

Implementors§

Source§

impl SleepProvider for SmolSleep

Available on crate feature async-smol and (crate features async-tokio or async-smol) only.
Source§

impl SleepProvider for SmolYield

Available on crate feature async-smol and (crate features async-tokio or async-smol) only.
Source§

impl SleepProvider for TokioSleep

Available on crate feature async-tokio and (crate features async-tokio or async-smol) only.
Source§

impl SleepProvider for TokioYield

Available on crate feature async-tokio and (crate features async-tokio or async-smol) only.
Source§

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