gloo_timers/lib.rs
1/*!
2
3Working with timers on the Web: `setTimeout` and `setInterval`.
4
5These APIs come in two flavors:
6
71. a callback style (that more directly mimics the JavaScript APIs), and
82. a `Future`s and `Stream`s API.
9
10## Timeouts
11
12Timeouts fire once after a period of time (measured in milliseconds).
13
14### Timeouts with a Callback Function
15
16```no_run
17use gloo_timers::callback::Timeout;
18
19let timeout = Timeout::new(1_000, move || {
20 // Do something after the one second timeout is up!
21});
22
23// Since we don't plan on cancelling the timeout, call `forget`.
24timeout.forget();
25```
26
27### Timeouts as `Future`s
28
29With the `futures` feature enabled, a `future` module containing futures-based
30timers is exposed.
31
32*/
33#![cfg_attr(feature = "futures", doc = "```no_run")]
34#![cfg_attr(not(feature = "futures"), doc = "```ignore")]
35/*!
36use gloo_timers::future::TimeoutFuture;
37use wasm_bindgen_futures::spawn_local;
38
39// Spawn the `timeout` future on the local thread. If we just dropped it, then
40// the timeout would be cancelled with `clearTimeout`.
41spawn_local(async {
42 TimeoutFuture::new(1_000).await;
43 // Do something here after the one second timeout is up!
44});
45```
46
47## Intervals
48
49Intervals fire repeatedly every *n* milliseconds.
50
51### Intervals with a Callback Function
52
53TODO
54
55### Intervals as `Stream`s
56
57TODO
58
59 */
60
61#![deny(missing_docs, missing_debug_implementations)]
62
63pub mod callback;
64
65#[cfg(feature = "futures")]
66pub mod future;