zng/timer.rs
1//! App timers service and other types.
2//!
3//! The [`TIMERS`] service provides timers that operate directly off the app main loop.
4//!
5//! The example below creates a timer that elapses every 1 second using [`TIMERS.interval`]. The timer is a variable
6//! so it can be mapped to a value, in the example this is used to create a countdown variable that counts from
7//! 10 to 0 and then stops the timer.
8//!
9//! ```
10//! use zng::prelude::*;
11//! # let _scope = APP.defaults();
12//!
13//! let countdown = timer::TIMERS.interval(1.secs(), false).map(move |t| {
14//! let count = 10 - t.count();
15//! if count == 0 {
16//! t.stop();
17//! }
18//! count
19//! });
20//! ```
21//!
22//! Note that you can also use the [`task::deadline`] function to `.await` a deadline, in app threads this function
23//! uses the [`TIMERS`] service too.
24//!
25//! [`task::deadline`]: crate::task::deadline
26//! [`TIMERS.interval`]: TIMERS::interval
27//!
28//! # Full API
29//!
30//! See [`zng_app::timer`] for the full time API.
31//!
32
33pub use zng_app::timer::{
34 DeadlineArgs, DeadlineHandle, DeadlineVar, TIMERS, Timer, TimerArgs, TimerHandle, TimerVar, WeakDeadlineHandle, WeakTimerHandle,
35};