Skip to main content

TimerHandle

Struct TimerHandle 

Source
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

Source

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).

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> TimerHandle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more