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§
- Deadline
Args - Arguments for the handler of
on_deadline. - Deadline
Handle - Represents a
on_deadlinehandler. - TIMERS
- App timers, deadlines and timeouts.
- Timer
- Represents a timer state in a
TimerVaror interval handler. - Timer
Args - Arguments for an
on_intervalhandler. - Timer
Handle - Represents a
on_intervalhandler. - Weak
Deadline Handle - Weak
DeadlineHandle - Weak
Timer Handle - Weak
TimerHandle.
Type Aliases§
- Deadline
Var - A
deadlinetimer. - Timer
Var - An
intervaltimer.