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

#277 in WebAssembly

Download history 182324/week @ 2023-12-04 166114/week @ 2023-12-11 145066/week @ 2023-12-18 79909/week @ 2023-12-25 130837/week @ 2024-01-01 176358/week @ 2024-01-08 182000/week @ 2024-01-15 190971/week @ 2024-01-22 207476/week @ 2024-01-29 192567/week @ 2024-02-05 199241/week @ 2024-02-12 199655/week @ 2024-02-19 214874/week @ 2024-02-26 213317/week @ 2024-03-04 196553/week @ 2024-03-11 215423/week @ 2024-03-18

849,913 downloads per month
Used in 2,831 crates (55 directly)

MIT/Apache

17KB
155 lines

gloo-timers

Crates.io version Download docs.rs docs

API Docs | Contributing | Chat

Built with 🦀🕸 by The Rust and WebAssembly Working Group

Working with timers on the Web: setTimeout and setInterval.

These APIs come in two flavors:

  1. a callback style (that more directly mimics the JavaScript APIs), and
  2. a Futures and Streams 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

~1–1.7MB
~32K SLoC