Module timer

Module timer 

Source
Expand description

App timers service and other types.

The TIMERS service provides timers that operate directly off the app main loop.

The example below creates a timer that elapses every 1 second using TIMERS.interval. The timer is a variable so it can be mapped to a value, in the example this is used to create a countdown variable that counts from 10 to 0 and then stops the timer.

use zng::prelude::*;

let countdown = timer::TIMERS.interval(1.secs(), false).map(move |t| {
    let count = 10 - t.count();
    if count == 0 {
        t.stop();
    }
    count
}); }

Note that you can also use the task::deadline function to .await a deadline, in app threads this function uses the TIMERS service too.

§Full API

See zng_app::timer for the full time API.

Structs§

DeadlineArgs
Arguments for the handler of on_deadline.
DeadlineHandle
Represents a on_deadline handler.
TIMERS
App timers, deadlines and timeouts.
Timer
Represents a timer state in a TimerVar or interval handler.
TimerArgs
Arguments for an on_interval handler.
TimerHandle
Represents a on_interval handler.
WeakDeadlineHandle
Weak DeadlineHandle
WeakTimerHandle
Weak TimerHandle.

Type Aliases§

DeadlineVar
A deadline timer.
TimerVar
An interval timer.