Clock

Trait Clock 

Source
pub trait Clock {
    // Required method
    fn now_ms(&self) -> u64;

    // Provided method
    fn poll_delay_until(
        &self,
        cx: &mut Context<'_>,
        deadline_ms: u64,
    ) -> Poll<()> { ... }
}
Expand description

Monotonic millisecond clock.

Required Methods§

Source

fn now_ms(&self) -> u64

Return milliseconds since an arbitrary monotonic epoch.

Provided Methods§

Source

fn poll_delay_until(&self, cx: &mut Context<'_>, deadline_ms: u64) -> Poll<()>

Poll a delay that completes when the monotonic clock reaches deadline_ms.

Returns Poll::Ready(()) if the deadline has already passed. Otherwise the implementation should register cx.waker() with a platform timer and return Poll::Pending.

The default implementation returns Ready(()) immediately, which causes callers to busy-poll on timer deadlines. Platform clocks backed by a real timer (tokio, embassy, etc.) should override this.

Implementors§