pub struct TimerHandle { /* private fields */ }Expand description
Cheap, clonable submission side of a DelayedTimer — the seam route for
deferred (SDLY/ODLY/watchdog-style) hand-offs.
Implementations§
Source§impl TimerHandle
impl TimerHandle
Sourcepub fn schedule(
&self,
delay: Duration,
priority: CallbackPriority,
cb: Callback,
)
pub fn schedule( &self, delay: Duration, priority: CallbackPriority, cb: Callback, )
Schedule deferred work cb to be enqueued on priority after delay.
Returns immediately — the callback runs on a pool worker no earlier than
delay from now. Port of callbackRequestDelayed (callback.c:410).
Sourcepub fn schedule_wake(&self, delay: Duration, cb: Callback) -> Option<WakeKey>
pub fn schedule_wake(&self, delay: Duration, cb: Callback) -> Option<WakeKey>
Schedule a non-blocking wakeup cb to run inline on the timer thread
after delay — the sleep/interval waker path. cb MUST be trivial
and non-blocking (only a waker wake(): an unpark or a tokio
task-schedule); it runs on the single timer thread and delays every later
deadline until it returns.
This exists so a spawned future that awaits sleep is never blocked by
its own wake: running it on the timer thread frees the band from the dual
role of “run futures” AND “wake them”. It is what closed the sleep-wake
self-deadlock (bug_pattern rtems-exec-sleep-wake-band-deadlock), back
when future_exec parked a worker per future for the future’s whole
life; that executor is now cooperative and holds a worker only across a
single poll, but a wake still costs no worker here.
The returned WakeKey is the caller’s claim on the queued entry, and
the caller MUST pass it to cancel_wake when it
stops caring about the wakeup. None means the timer had already shut
down and cb was dropped unscheduled — there is nothing to cancel.
Sourcepub fn cancel_wake(&self, key: WakeKey)
pub fn cancel_wake(&self, key: WakeKey)
Drop the wake entry filed under key now, instead of leaving it queued
until its deadline. Cancelling an entry that has already fired is a
no-op, so a caller never has to know which happened first.
Unlike schedule, which is C’s fire-and-forget
callbackRequestDelayed, a wake belongs to the sleeper that armed it:
the entry holds a clone of the sleeper’s shared cell, so an uncancelled
entry keeps that cell — and the OS mutex inside it — alive for the whole
remaining delay even though the sleeper is long gone.
Sourcepub fn scheduled_count(&self) -> usize
pub fn scheduled_count(&self) -> usize
How many entries are queued. For tests and on-target probes: the per-sleep retention this queue used to carry is only visible as a count.
Trait Implementations§
Source§impl Clone for TimerHandle
impl Clone for TimerHandle
Source§fn clone(&self) -> TimerHandle
fn clone(&self) -> TimerHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more