Skip to main content

Timer

Trait Timer 

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

A source of futures that complete after a delay.

Separate from Spawn because waiting and executing are different capabilities: a caller that is already inside an async task needs the timer, not the executor.

Required Methods§

Source

fn sleep(&self, duration: Duration) -> BoxFuture<()>

Returns a future that completes once duration has elapsed.

Creating the future must not require an ambient executor context, so a caller can build it anywhere and await it wherever it likes.

Implementors§