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, now: Deadline, scheduled: Deadline, scope: &mut Scope<Self::Context>) -> Deadline; }
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, now: Deadline, scheduled: Deadline, scope: &mut Scope<Self::Context>) -> Deadline
Calculates the next wakeup time
now
-- is time when event processing was started, this is provided
for performance reasons
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 now + Duration::seconds(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::seconds(interval)
Note, in both cases mio will run timeout handler on the next tick of the timer, which means +200 ms by default.
Implementors
impl<T: SimpleTimer> Timer for Interval<T>