pub struct TimerRegistry { /* private fields */ }Expand description
A registry for tracking timers by identifier.
Implementations§
Source§impl TimerRegistry
impl TimerRegistry
Sourcepub async fn insert(&self, timer: Timer) -> u64
pub async fn insert(&self, timer: Timer) -> u64
Inserts an existing timer and returns its identifier.
Sourcepub async fn start_once<F>(
&self,
delay: Duration,
callback: F,
) -> Result<(u64, Timer), TimerError>where
F: TimerCallback + 'static,
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.
Sourcepub async fn start_recurring<F>(
&self,
interval: Duration,
callback: F,
expiration_count: Option<usize>,
) -> Result<(u64, Timer), TimerError>where
F: TimerCallback + 'static,
pub async fn start_recurring<F>(
&self,
interval: Duration,
callback: F,
expiration_count: Option<usize>,
) -> Result<(u64, Timer), TimerError>where
F: TimerCallback + 'static,
Starts and registers a recurring timer.
Sourcepub async fn remove(&self, id: u64) -> Option<Timer>
pub async fn remove(&self, id: u64) -> Option<Timer>
Removes a timer from the registry and returns it.
Sourcepub async fn contains(&self, id: u64) -> bool
pub async fn contains(&self, id: u64) -> bool
Returns true when the registry tracks the given timer identifier.
Sourcepub async fn stop(&self, id: u64) -> Result<Option<TimerOutcome>, TimerError>
pub async fn stop(&self, id: u64) -> Result<Option<TimerOutcome>, TimerError>
Stops a timer by identifier when it exists.
Sourcepub async fn cancel(&self, id: u64) -> Result<Option<TimerOutcome>, TimerError>
pub async fn cancel(&self, id: u64) -> Result<Option<TimerOutcome>, TimerError>
Cancels a timer by identifier when it exists.
Sourcepub async fn pause(&self, id: u64) -> Result<bool, TimerError>
pub async fn pause(&self, id: u64) -> Result<bool, TimerError>
Pauses a timer by identifier when it exists.
Sourcepub async fn resume(&self, id: u64) -> Result<bool, TimerError>
pub async fn resume(&self, id: u64) -> Result<bool, TimerError>
Resumes a timer by identifier when it exists.
Sourcepub async fn join_all(&self) -> Vec<(u64, TimerOutcome)>
pub async fn join_all(&self) -> Vec<(u64, TimerOutcome)>
Waits for all tracked timers that have a joinable outcome.
Sourcepub async fn cancel_all(&self)
pub async fn cancel_all(&self)
Cancels all timers currently tracked by the registry.
Sourcepub async fn resume_all(&self)
pub async fn resume_all(&self)
Resumes all paused timers currently tracked by the registry.
Sourcepub async fn active_ids(&self) -> Vec<u64>
pub async fn active_ids(&self) -> Vec<u64>
Lists all active timers.
Trait Implementations§
Source§impl Clone for TimerRegistry
impl Clone for TimerRegistry
Source§fn clone(&self) -> TimerRegistry
fn clone(&self) -> TimerRegistry
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for TimerRegistry
impl Default for TimerRegistry
Source§fn default() -> TimerRegistry
fn default() -> TimerRegistry
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for TimerRegistry
impl !RefUnwindSafe for TimerRegistry
impl Send for TimerRegistry
impl Sync for TimerRegistry
impl Unpin for TimerRegistry
impl UnsafeUnpin for TimerRegistry
impl !UnwindSafe for TimerRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more