pub struct TokioTimer { /* private fields */ }tokio only.Expand description
An asynchronous timer backed by one Tokio runtime time driver.
The timer retains the source clock’s exact domain, origin, and runtime
capability. It enters that runtime briefly to sample time and create each
Tokio sleep, so registration does not depend on the caller’s ambient
runtime. The returned future may be polled elsewhere, but the retained
runtime must remain alive and driven until the future completes or is
dropped. If it shuts down first, a pending future returns
TimerUnavailableError::RuntimeShuttingDown.
§Resolution
Logical deadlines preserve the full Duration, but Tokio drives pending
sleeps with millisecond-level scheduling granularity. This timer is not for
high-resolution timing, and platform scheduling may add further delay.
Implementations§
Source§impl TokioTimer
impl TokioTimer
Sourcepub fn from_handle(runtime: Handle) -> Self
pub fn from_handle(runtime: Handle) -> Self
Creates a timer backed by an explicit runtime handle.
This constructor does not depend on an ambient Tokio runtime.
§Parameters
runtime- Runtime capability providing the clock and time driver.
§Returns
A timer with a new clock domain backed by runtime.
§Panics
Panics if all process-wide clock-domain identifiers are exhausted.
Sourcepub fn try_current() -> Result<Self, TokioRuntimeError>
pub fn try_current() -> Result<Self, TokioRuntimeError>
Tries to create a timer by capturing the current Tokio runtime.
§Returns
A timer with a new clock domain retaining the current runtime’s handle.
§Errors
Returns TokioRuntimeError::NotEntered when no Tokio runtime is
entered.
§Panics
Panics if all process-wide clock-domain identifiers are exhausted.
Sourcepub fn from_clock(clock: &TokioMonotonicClock) -> Self
pub fn from_clock(clock: &TokioMonotonicClock) -> Self
Trait Implementations§
Source§impl Debug for TokioTimer
impl Debug for TokioTimer
Source§impl Timer for TokioTimer
impl Timer for TokioTimer
Source§fn clock(&self) -> &dyn MonotonicClock
fn clock(&self) -> &dyn MonotonicClock
Returns the private same-domain Tokio 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>
Creates a Tokio sleep with a fixed absolute deadline.
§Parameters
deadline- Deadline in this timer’s clock domain.
§Returns
A future waiting for the fixed deadline, or an immediately ready future
for a reached deadline in the retained runtime’s time domain. If the
retained runtime shuts down before a pending future completes, that
future returns TimerUnavailableError::RuntimeShuttingDown.
§Errors
Returns a domain mismatch or instant overflow before runtime access.
Returns TimerUnavailableError::TimeDriverDisabled when a future
deadline requires a time driver that the retained runtime did not
enable. Reached deadlines do not require a time driver.
In unwind builds Tokio’s panic hook may observe this disabled-driver
condition before it is converted into the structured error. In
panic = "abort" builds Tokio aborts before conversion is possible.
Source§fn after(&self, duration: Duration) -> Result<TimerFuture, TimeError>
fn after(&self, duration: Duration) -> Result<TimerFuture, TimeError>
Registers a notification after a duration in the retained Tokio runtime.
§Parameters
duration- Duration from the retained runtime’s current instant.
§Returns
A future that becomes ready when the fixed deadline is reached.
If the retained runtime shuts down before that happens, the future
returns TimerUnavailableError::RuntimeShuttingDown.
§Errors
Returns TimeError::InstantOverflow when the relative deadline cannot
be represented, or TimerUnavailableError::TimeDriverDisabled when a
nonzero future deadline requires a disabled time driver.
In unwind builds Tokio’s panic hook may observe this disabled-driver
condition before it is converted into the structured error. In
panic = "abort" builds Tokio aborts before conversion is possible.