pub type TimerVar = ReadOnlyArcVar<Timer>;
Expand description
An interval
timer.
This is a variable of type Timer
, it will update every time the timer elapses.
Drop all clones of this variable to stop the timer, you can also control the timer
with methods in the Timer
value even though the variable is read-only.
let timer: TimerVar = TIMERS.interval(1.secs(), false);
text = timer.map(|d| match 20 - d.count() {
0 => {
d.stop();
formatx!("Done!")
},
1 => formatx!("1 second left"),
s => formatx!("{s} seconds left")
});
In the example above the variable updates every second and stops after 20 seconds have elapsed. The variable
is mapped to a text and controls the timer from inside the mapping closure. See Var<T>
for other things you
can do with variables, including .await
for updates. Also see Timer
for more timer control methods.
Aliased Type§
struct TimerVar(/* private fields */);