Skip to main content

Timer

Struct Timer 

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

Timer handle for managing one-time and recurring tasks.

Implementations§

Source§

impl Timer

Source

pub fn new() -> Self

Creates a new timer.

Source

pub fn new_silent() -> Self

Creates a new timer with broadcast events disabled.

Source

pub fn once(delay: Duration) -> TimerBuilder

Creates a timer builder configured for a one-time run.

Source

pub fn at(deadline: Instant) -> TimerBuilder

Creates a timer builder configured for a one-time run at a deadline.

Source

pub fn recurring(schedule: RecurringSchedule) -> TimerBuilder

Creates a timer builder configured for a recurring schedule.

Source

pub fn subscribe(&self) -> TimerEvents

Subscribes to future timer events.

Source

pub fn completion(&self) -> TimerCompletion

Subscribes to completed runs without loss.

Source

pub async fn start_once<F>( &self, delay: Duration, callback: F, ) -> Result<u64, TimerError>
where F: TimerCallback + 'static,

Starts a one-time timer.

Source

pub async fn start_once_fn<F, Fut>( &self, delay: Duration, callback: F, ) -> Result<u64, TimerError>
where F: Fn() -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), TimerError>> + Send + 'static,

Starts a one-time timer from an async closure.

Source

pub async fn start_at<F>( &self, deadline: Instant, callback: F, ) -> Result<u64, TimerError>
where F: TimerCallback + 'static,

Starts a one-time timer that fires at the provided deadline.

Source

pub async fn start_at_fn<F, Fut>( &self, deadline: Instant, callback: F, ) -> Result<u64, TimerError>
where F: Fn() -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), TimerError>> + Send + 'static,

Starts a one-time timer from an async closure at the provided deadline.

Source

pub async fn start_recurring<F>( &self, schedule: RecurringSchedule, callback: F, ) -> Result<u64, TimerError>
where F: TimerCallback + 'static,

Starts a recurring timer with the provided schedule.

Source

pub async fn start_recurring_fn<F, Fut>( &self, schedule: RecurringSchedule, callback: F, ) -> Result<u64, TimerError>
where F: Fn() -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), TimerError>> + Send + 'static,

Starts a recurring timer from an async closure.

Source

pub async fn pause(&self) -> Result<(), TimerError>

Pauses a running timer.

Source

pub async fn request_pause(&self) -> Result<(), TimerError>

Requests that the current run pause after the current callback or sleep edge.

Source

pub async fn resume(&self) -> Result<(), TimerError>

Resumes a paused timer.

Source

pub async fn request_resume(&self) -> Result<(), TimerError>

Requests that a paused timer resume.

Source

pub async fn stop(&self) -> Result<TimerOutcome, TimerError>

Stops the timer after the current callback finishes.

Source

pub async fn request_stop(&self) -> Result<(), TimerError>

Requests a graceful stop without waiting for the outcome.

Source

pub async fn cancel(&self) -> Result<TimerOutcome, TimerError>

Cancels the timer immediately and aborts the callback task.

Source

pub async fn request_cancel(&self) -> Result<(), TimerError>

Requests cancellation without aborting the active callback task.

Source

pub async fn adjust_interval( &self, new_interval: Duration, ) -> Result<(), TimerError>

Adjusts the interval of a running or paused timer.

Source

pub async fn request_adjust_interval( &self, new_interval: Duration, ) -> Result<(), TimerError>

Requests an interval adjustment for the current run.

Source

pub async fn join(&self) -> Result<TimerOutcome, TimerError>

Waits for the current run and returns the completed outcome.

Source

pub async fn wait(&self)

Waits until the current run has completed or been stopped.

Source

pub async fn get_statistics(&self) -> TimerStatistics

Gets the timer’s statistics for the current or most recent run.

Source

pub async fn get_state(&self) -> TimerState

Gets the current state of the timer.

Source

pub async fn get_interval(&self) -> Duration

Gets the timer interval for the current or next run.

Source

pub async fn get_expiration_count(&self) -> Option<usize>

Gets the configured expiration count for the current or next run.

Source

pub async fn get_last_error(&self) -> Option<TimerError>

Gets the most recent callback error observed for the current or most recent run.

Source

pub async fn metadata(&self) -> TimerMetadata

Returns the metadata currently associated with the timer.

Source

pub async fn label(&self) -> Option<String>

Returns the current label, if one has been assigned.

Source

pub async fn set_label(&self, label: impl Into<String>)

Sets the timer label used for diagnostics and registry introspection.

Source

pub async fn set_tag(&self, key: impl Into<String>, value: impl Into<String>)

Sets or replaces a metadata tag on the timer.

Source

pub async fn snapshot(&self) -> TimerSnapshot

Captures a snapshot of the timer’s current observable state.

Source

pub async fn last_outcome(&self) -> Option<TimerOutcome>

Gets the most recent completed run outcome.

Source

pub fn set_events_enabled(&self, enabled: bool)

Enables or disables broadcast event emission for future runtime events.

Trait Implementations§

Source§

impl Clone for Timer

Source§

fn clone(&self) -> Timer

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for Timer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Timer

§

impl !RefUnwindSafe for Timer

§

impl Send for Timer

§

impl Sync for Timer

§

impl Unpin for Timer

§

impl UnsafeUnpin for Timer

§

impl !UnwindSafe for Timer

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