pub trait PeriodicState {
    type Id: Hash + Clone + Eq;

    // Required methods
    fn id(&self) -> &Self::Id;
    fn trigger(self) -> TimerReturn<Self>
       where Self: Sized;
}
Expand description

A trait for state that can be triggered more than once once

This is different from oneshot timers, for the a similar reason to that why the FnOnce trait is different from the Fn trait. In effect, periodic state needs to be able to produce a new instance of itself for the next period, while oneshot state does not.

Required Associated Types§

source

type Id: Hash + Clone + Eq

The type of the unique id of the outstanding timeout

Required Methods§

source

fn id(&self) -> &Self::Id

A reference to the id associated with this state

source

fn trigger(self) -> TimerReturn<Self>where Self: Sized,

Trigger should be called by the timer implementation when the timeout has expired.

The method can be used for custom expiry actions, but it is strongly recommended to keep these quick, as long actions can delay the execution of later timers.

For periodic actions the trigger actions may mutate (or replace) the state of the timer entry itself. Together with the ability to prevent reschedulling, this can be used to implement “counter”-style timers, that happen a fixed number of times before being dropped automatically.

Implementors§

source§

impl<I> PeriodicState for PeriodicClosureState<I>where I: Hash + Clone + Eq,

§

type Id = I