Skip to main content

TokioTimer

Struct TokioTimer 

Source
pub struct TokioTimer { /* private fields */ }
Available on crate feature 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

Source

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.

Source

pub fn current() -> Self

Creates a timer by capturing the currently entered Tokio runtime.

§Returns

A timer with a new clock domain retaining the current runtime’s handle.

§Panics

Panics when no Tokio runtime is entered or all process-wide clock-domain identifiers are exhausted.

Source

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.

Source

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

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

§Parameters
  • clock - Tokio clock whose domain, origin, and runtime capability apply.
§Returns

A timer retaining an independent same-domain clock handle.

Trait Implementations§

Source§

impl Debug for TokioTimer

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Timer for TokioTimer

Source§

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>

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>

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.

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.