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
impl StdTimer
Sourcepub fn new() -> Self
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.
Sourcepub fn from_clock(clock: &StdMonotonicClock) -> Self
pub fn from_clock(clock: &StdMonotonicClock) -> Self
Trait Implementations§
Source§impl Timer for StdTimer
impl Timer for StdTimer
Source§fn clock(&self) -> &dyn MonotonicClock
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>
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>
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.