Trait rotor_tools::timer::Timer [] [src]

pub trait Timer {
    type Context;
    fn timeout(self, scope: &mut Scope<Self::Context>) -> Self;
    fn next_wakeup_time(&self, scheduled: Time, scope: &mut Scope<Self::Context>) -> Time;
}

A protocol for the state machine that put into the Ticker

Associated Types

type Context

Required Methods

fn timeout(self, scope: &mut Scope<Self::Context>) -> Self

Called when time elapsed

fn next_wakeup_time(&self, scheduled: Time, scope: &mut Scope<Self::Context>) -> Time

Calculates the next wakeup time

scheduled -- time when event had to occur

There are two options to calculate the time. If you just need to run something on occasion use simply: ignore scope.now() + Duration::new(interval, )

Or if you need to run strict number of times and as close as possible to the multiple of the interval time. You may want: ignore scheduled + Duration::new(interval, 0)

Note, in both cases mio will run timeout handler on the next tick of the timer, which means +200 ms by default.

Implementors