Skip to main content

Timer

Trait Timer 

Source
pub trait Timer:
    Send
    + Sync
    + 'static {
    // Required methods
    fn sleep(&self, dur: Duration) -> Pin<Box<dyn Future<Output = ()> + Send>>;
    fn next_tick(&self) -> Pin<Box<dyn Future<Output = ()> + Send>>;
}
Expand description

Async scheduling primitive. Single port for “wait N ms” / “yield event-loop tick”.

The futures are written out as Pin<Box<dyn Future + Send>> — every name in them is core’s. An alias from futures would put a foreign crate on this vocabulary’s surface (RFC_202610142318 R4); futures::future::BoxFuture is the same type, so an implementor may still spell it that way.

Required Methods§

Source

fn sleep(&self, dur: Duration) -> Pin<Box<dyn Future<Output = ()> + Send>>

A future that completes once dur has elapsed on this timer.

Source

fn next_tick(&self) -> Pin<Box<dyn Future<Output = ()> + Send>>

A future that completes on the runtime’s next scheduling turn — a yield, not a delay.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§