Skip to main content

TimerRegistry

Struct TimerRegistry 

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

A registry for tracking timers by identifier.

Implementations§

Source§

impl TimerRegistry

Source

pub fn new() -> Self

Creates a new timer registry.

Source

pub async fn insert(&self, timer: Timer) -> u64

Inserts an existing timer and returns its identifier.

Source

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

Starts and registers a one-time timer.

Source

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

Starts and registers a one-time timer at a deadline.

Source

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

Starts and registers a recurring timer.

Source

pub async fn remove(&self, id: u64) -> Option<Timer>

Removes a timer from the registry and returns it.

Source

pub async fn contains(&self, id: u64) -> bool

Returns true when the registry tracks the given timer identifier.

Source

pub async fn stop(&self, id: u64) -> Result<Option<TimerOutcome>, TimerError>

Stops a timer by identifier when it exists.

Source

pub async fn cancel(&self, id: u64) -> Result<Option<TimerOutcome>, TimerError>

Cancels a timer by identifier when it exists.

Source

pub async fn pause(&self, id: u64) -> Result<bool, TimerError>

Pauses a timer by identifier when it exists.

Source

pub async fn resume(&self, id: u64) -> Result<bool, TimerError>

Resumes a timer by identifier when it exists.

Source

pub async fn stop_all(&self)

Stops all timers currently tracked by the registry.

Source

pub async fn pause_all(&self)

Pauses all running timers currently tracked by the registry.

Source

pub async fn join_all(&self) -> Vec<(u64, TimerOutcome)>

Waits for all tracked timers that have a joinable outcome.

Source

pub async fn cancel_all(&self)

Cancels all timers currently tracked by the registry.

Source

pub async fn resume_all(&self)

Resumes all paused timers currently tracked by the registry.

Source

pub async fn active_ids(&self) -> Vec<u64>

Lists all active timers.

Source

pub async fn get(&self, id: u64) -> Option<Timer>

Retrieves a timer by ID.

Source

pub async fn snapshot(&self, id: u64) -> Option<RegisteredTimer>

Returns a snapshot of a tracked timer by identifier.

Source

pub async fn list(&self) -> Vec<RegisteredTimer>

Lists snapshots for all tracked timers.

Source

pub async fn find_by_label(&self, label: &str) -> Vec<u64>

Returns the identifiers for timers carrying a matching label.

Source

pub async fn len(&self) -> usize

Returns the number of tracked timers.

Source

pub async fn is_empty(&self) -> bool

Returns true when the registry is empty.

Source

pub async fn clear(&self) -> usize

Removes all tracked timers and returns the number removed.

Trait Implementations§

Source§

impl Clone for TimerRegistry

Source§

fn clone(&self) -> TimerRegistry

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 TimerRegistry

Source§

fn default() -> TimerRegistry

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

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