Skip to main content

Timer

Trait Timer 

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

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

Both methods return BoxFuture, so the port is Send on native targets and needs no Send bridge in the browser.

Required Methods§

Source

fn sleep(&self, dur: Duration) -> BoxFuture<'static, ()>

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

Source

fn next_tick(&self) -> BoxFuture<'static, ()>

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§

Source§

impl Timer for AdvanceableTimer

Available on crate feature mock only.
Source§

impl Timer for NativeTimer

Available on crate feature native only.