pub trait TimerContext<Id>: InstantContext {
    // Required methods
    fn schedule_timer_instant(
        &mut self,
        time: Self::Instant,
        id: Id
    ) -> Option<Self::Instant>;
    fn cancel_timer(&mut self, id: Id) -> Option<Self::Instant>;
    fn cancel_timers_with<F: FnMut(&Id) -> bool>(&mut self, f: F);
    fn scheduled_instant(&self, id: Id) -> Option<Self::Instant>;

    // Provided method
    fn schedule_timer(
        &mut self,
        duration: Duration,
        id: Id
    ) -> Option<Self::Instant> { ... }
}
Expand description

A context that supports scheduling timers.

Required Methods§

source

fn schedule_timer_instant( &mut self, time: Self::Instant, id: Id ) -> Option<Self::Instant>

Schedule a timer to fire at some point in the future.

schedule_timer schedules the given timer to be fired at time, overwriting any previous timer with the same ID.

If there was previously a timer with that ID, return the time at which is was scheduled to fire.

source

fn cancel_timer(&mut self, id: Id) -> Option<Self::Instant>

Cancel a timer.

If a timer with the given ID exists, it is canceled and the instant at which it was scheduled to fire is returned.

source

fn cancel_timers_with<F: FnMut(&Id) -> bool>(&mut self, f: F)

Cancel all timers which satisfy a predicate.

cancel_timers_with calls f on each scheduled timer, and cancels any timer for which f returns true.

source

fn scheduled_instant(&self, id: Id) -> Option<Self::Instant>

Get the instant a timer will fire, if one is scheduled.

Returns the Instant a timer with ID id will be invoked. If no timer with the given ID exists, scheduled_instant will return None.

Provided Methods§

source

fn schedule_timer( &mut self, duration: Duration, id: Id ) -> Option<Self::Instant>

Schedule a timer to fire after some duration.

schedule_timer schedules the given timer to be fired after duration has elapsed, overwriting any previous timer with the same ID.

If there was previously a timer with that ID, return the time at which is was scheduled to fire.

§Panics

schedule_timer may panic if duration is large enough that self.now() + duration overflows.

Object Safety§

This trait is not object safe.

Implementors§