pub struct Timer { /* private fields */ }Expand description
Timer handle for managing one-time and recurring tasks.
Implementations§
Source§impl Timer
impl Timer
Sourcepub fn new_silent() -> Self
pub fn new_silent() -> Self
Creates a new timer with broadcast events disabled.
Sourcepub fn once(delay: Duration) -> TimerBuilder
pub fn once(delay: Duration) -> TimerBuilder
Creates a timer builder configured for a one-time run.
Sourcepub fn at(deadline: Instant) -> TimerBuilder
pub fn at(deadline: Instant) -> TimerBuilder
Creates a timer builder configured for a one-time run at a deadline.
Sourcepub fn recurring(schedule: RecurringSchedule) -> TimerBuilder
pub fn recurring(schedule: RecurringSchedule) -> TimerBuilder
Creates a timer builder configured for a recurring schedule.
Sourcepub fn subscribe(&self) -> TimerEvents
pub fn subscribe(&self) -> TimerEvents
Subscribes to future timer events.
Sourcepub fn completion(&self) -> TimerCompletion
pub fn completion(&self) -> TimerCompletion
Subscribes to completed runs without loss.
Sourcepub async fn start_once<F>(
&self,
delay: Duration,
callback: F,
) -> Result<u64, TimerError>where
F: TimerCallback + 'static,
pub async fn start_once<F>(
&self,
delay: Duration,
callback: F,
) -> Result<u64, TimerError>where
F: TimerCallback + 'static,
Starts a one-time timer.
Sourcepub async fn start_once_fn<F, Fut>(
&self,
delay: Duration,
callback: F,
) -> Result<u64, TimerError>
pub async fn start_once_fn<F, Fut>( &self, delay: Duration, callback: F, ) -> Result<u64, TimerError>
Starts a one-time timer from an async closure.
Sourcepub async fn start_at<F>(
&self,
deadline: Instant,
callback: F,
) -> Result<u64, TimerError>where
F: TimerCallback + 'static,
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.
Sourcepub async fn start_at_fn<F, Fut>(
&self,
deadline: Instant,
callback: F,
) -> Result<u64, TimerError>
pub async fn start_at_fn<F, Fut>( &self, deadline: Instant, callback: F, ) -> Result<u64, TimerError>
Starts a one-time timer from an async closure at the provided deadline.
Sourcepub async fn start_recurring<F>(
&self,
schedule: RecurringSchedule,
callback: F,
) -> Result<u64, TimerError>where
F: TimerCallback + 'static,
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.
Sourcepub async fn start_recurring_fn<F, Fut>(
&self,
schedule: RecurringSchedule,
callback: F,
) -> Result<u64, TimerError>
pub async fn start_recurring_fn<F, Fut>( &self, schedule: RecurringSchedule, callback: F, ) -> Result<u64, TimerError>
Starts a recurring timer from an async closure.
Sourcepub async fn pause(&self) -> Result<(), TimerError>
pub async fn pause(&self) -> Result<(), TimerError>
Pauses a running timer.
Sourcepub async fn request_pause(&self) -> Result<(), TimerError>
pub async fn request_pause(&self) -> Result<(), TimerError>
Requests that the current run pause after the current callback or sleep edge.
Sourcepub async fn resume(&self) -> Result<(), TimerError>
pub async fn resume(&self) -> Result<(), TimerError>
Resumes a paused timer.
Sourcepub async fn request_resume(&self) -> Result<(), TimerError>
pub async fn request_resume(&self) -> Result<(), TimerError>
Requests that a paused timer resume.
Sourcepub async fn stop(&self) -> Result<TimerOutcome, TimerError>
pub async fn stop(&self) -> Result<TimerOutcome, TimerError>
Stops the timer after the current callback finishes.
Sourcepub async fn request_stop(&self) -> Result<(), TimerError>
pub async fn request_stop(&self) -> Result<(), TimerError>
Requests a graceful stop without waiting for the outcome.
Sourcepub async fn cancel(&self) -> Result<TimerOutcome, TimerError>
pub async fn cancel(&self) -> Result<TimerOutcome, TimerError>
Cancels the timer immediately and aborts the callback task.
Sourcepub async fn request_cancel(&self) -> Result<(), TimerError>
pub async fn request_cancel(&self) -> Result<(), TimerError>
Requests cancellation without aborting the active callback task.
Sourcepub async fn adjust_interval(
&self,
new_interval: Duration,
) -> Result<(), TimerError>
pub async fn adjust_interval( &self, new_interval: Duration, ) -> Result<(), TimerError>
Adjusts the interval of a running or paused timer.
Sourcepub async fn request_adjust_interval(
&self,
new_interval: Duration,
) -> Result<(), TimerError>
pub async fn request_adjust_interval( &self, new_interval: Duration, ) -> Result<(), TimerError>
Requests an interval adjustment for the current run.
Sourcepub async fn join(&self) -> Result<TimerOutcome, TimerError>
pub async fn join(&self) -> Result<TimerOutcome, TimerError>
Waits for the current run and returns the completed outcome.
Sourcepub async fn get_statistics(&self) -> TimerStatistics
pub async fn get_statistics(&self) -> TimerStatistics
Gets the timer’s statistics for the current or most recent run.
Sourcepub async fn get_state(&self) -> TimerState
pub async fn get_state(&self) -> TimerState
Gets the current state of the timer.
Sourcepub async fn get_interval(&self) -> Duration
pub async fn get_interval(&self) -> Duration
Gets the timer interval for the current or next run.
Sourcepub async fn get_expiration_count(&self) -> Option<usize>
pub async fn get_expiration_count(&self) -> Option<usize>
Gets the configured expiration count for the current or next run.
Sourcepub async fn get_last_error(&self) -> Option<TimerError>
pub async fn get_last_error(&self) -> Option<TimerError>
Gets the most recent callback error observed for the current or most recent run.
Sourcepub async fn metadata(&self) -> TimerMetadata
pub async fn metadata(&self) -> TimerMetadata
Returns the metadata currently associated with the timer.
Sourcepub async fn label(&self) -> Option<String>
pub async fn label(&self) -> Option<String>
Returns the current label, if one has been assigned.
Sourcepub async fn set_label(&self, label: impl Into<String>)
pub async fn set_label(&self, label: impl Into<String>)
Sets the timer label used for diagnostics and registry introspection.
Sourcepub async fn set_tag(&self, key: impl Into<String>, value: impl Into<String>)
pub async fn set_tag(&self, key: impl Into<String>, value: impl Into<String>)
Sets or replaces a metadata tag on the timer.
Sourcepub async fn snapshot(&self) -> TimerSnapshot
pub async fn snapshot(&self) -> TimerSnapshot
Captures a snapshot of the timer’s current observable state.
Sourcepub async fn last_outcome(&self) -> Option<TimerOutcome>
pub async fn last_outcome(&self) -> Option<TimerOutcome>
Gets the most recent completed run outcome.
Sourcepub fn set_events_enabled(&self, enabled: bool)
pub fn set_events_enabled(&self, enabled: bool)
Enables or disables broadcast event emission for future runtime events.