Skip to main content

StdTimer

Struct StdTimer 

Source
pub struct StdTimer { /* private fields */ }
Expand description

A real-time asynchronous timer backed by std::time::Instant.

Every standard Timer in the process shares one scheduler worker. The worker starts lazily with the first future registration and remains parked while idle so later registrations do not need to create another native thread. If that worker exits unexpectedly, its active futures are awakened and return TimeError::TimerUnavailable with TimerUnavailableError::SchedulerWorkerTerminated instead of remaining pending or reporting false deadline completion. A later registration starts a replacement worker generation.

Implementations§

Source§

impl StdTimer

Source

pub fn new() -> Self

Creates a timer backed by a new standard monotonic clock.

§Returns

A timer with a fresh clock domain and the process-wide scheduler.

Source

pub fn from_clock(clock: &StdMonotonicClock) -> Self

Creates a timer sharing the supplied standard clock’s exact domain.

§Parameters
  • clock - Standard clock whose domain and origin drive this timer.
§Returns

A timer retaining the process-wide lazy scheduler.

Trait Implementations§

Source§

impl Debug for StdTimer

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the retained clock without exposing scheduler internals.

§Parameters
  • formatter - Destination formatter.
§Returns

Ok(()) when formatting succeeds.

§Errors

Returns std::fmt::Error when the destination rejects output.

Source§

impl Default for StdTimer

Source§

fn default() -> Self

Creates a standard timer with a fresh clock domain.

§Returns

A standard timer with a newly allocated clock domain.

§Panics

Panics if all process-wide clock-domain identifiers are exhausted.

Source§

impl Timer for StdTimer

Source§

fn clock(&self) -> &dyn MonotonicClock

Returns the private same-domain standard clock handle.

§Returns

The monotonic clock driving this timer.

Source§

fn at(&self, deadline: MonotonicInstant) -> Result<TimerFuture, TimeError>

Eagerly registers an absolute deadline with the shared scheduler.

§Parameters
  • deadline - Deadline in this timer’s clock domain.
§Returns

A cancellation-safe future whose registration is already active, or an immediately ready future for a reached deadline. The future returns TimeError::TimerUnavailable with TimerUnavailableError::SchedulerWorkerTerminated when its scheduler worker exits unexpectedly.

§Errors

Returns a domain mismatch, native-instant overflow, or scheduler startup error before returning a future.

§Panics

Panics when scheduler registration identifiers or worker generations are exhausted, or an internal scheduler index invariant is violated.

Source§

fn after(&self, duration: Duration) -> Result<TimerFuture, TimeError>

Eagerly registers a relative deadline with the shared scheduler.

This implementation samples the native instant once, avoiding the monotonic-domain conversion required by the default trait method.

§Parameters
  • duration - Delay before the future becomes ready.
§Returns

A cancellation-safe future whose registration is already active, or an immediately ready future for a zero duration.

§Errors

Returns TimeError::InstantOverflow when the native deadline cannot be represented, or a scheduler startup error before returning a future.

§Panics

Panics when scheduler registration identifiers or worker generations are exhausted, or an internal scheduler index invariant is violated.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.