Skip to main content

Timer

Trait Timer 

Source
pub trait Timer {
    type Context;

    // Required methods
    fn timeout(self, scope: &mut Scope<'_, Self::Context>) -> Self;
    fn next_wakeup_time(
        &self,
        scheduled: Time,
        scope: &mut Scope<'_, Self::Context>,
    ) -> Time;
}
Expand description

A protocol for the state machine that put into the Ticker

Required Associated Types§

Required Methods§

Source

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

Called when time elapsed

Source

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:

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:

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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§