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§
Sourcefn now_ms(&self) -> u64
fn now_ms(&self) -> u64
Return milliseconds since the device booted.
Most of the stack only ever takes differences and would be happy
with any monotonic epoch, but PROP_UPTIME reports this value
directly, so the epoch is part of the contract: an implementation
backed by a clock that starts somewhere else MUST subtract its own
origin. A simulated device that emulates a reboot has to restart
this along with the rest of the hardware.
Provided Methods§
Sourcefn poll_delay_until(&self, cx: &mut Context<'_>, deadline_ms: u64) -> Poll<()>
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 MUST register cx.waker() with a platform timer and
return Poll::Pending, so the task is woken when the deadline elapses.
The default implementation has no real timer: it schedules an immediate
re-poll (via cx.waker().wake_by_ref()) and returns Poll::Pending, causing
the caller to busy-poll until the monotonic clock reaches the deadline.
This is correct but wastes CPU; platform clocks backed by a real timer
(tokio, embassy, etc.) MUST override this to sleep efficiently. A default
that returned Ready unconditionally would spin just as hard; one that
returned Pending without waking would stall timer-driven work entirely.