9 releases
| 0.3.0 | Aug 11, 2023 |
|---|---|
| 0.2.6 | Jan 21, 2023 |
| 0.2.5 | Nov 29, 2022 |
| 0.2.4 | Apr 13, 2022 |
| 0.1.0 | Sep 13, 2019 |
#54 in WebAssembly
2,640,282 downloads per month
Used in 4,051 crates
(147 directly)
17KB
155 lines
Working with timers on the Web: setTimeout and setInterval.
These APIs come in two flavors:
- a callback style (that more directly mimics the JavaScript APIs), and
- a
Futures andStreams API.
Timeouts
Timeouts fire once after a period of time (measured in milliseconds).
Timeouts with a Callback Function
use gloo_timers::callback::Timeout;
let timeout = Timeout::new(1_000, move || {
// Do something after the one second timeout is up!
});
// Since we don't plan on cancelling the timeout, call `forget`.
timeout.forget();
Timeouts as Futures
With the futures feature enabled, a future module containing futures-based
timers is exposed.
Dependencies
~0.7–1.4MB
~25K SLoC