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

#205 in WebAssembly

Download history 192193/week @ 2024-01-17 191988/week @ 2024-01-24 204020/week @ 2024-01-31 194263/week @ 2024-02-07 194927/week @ 2024-02-14 217411/week @ 2024-02-21 207741/week @ 2024-02-28 208674/week @ 2024-03-06 201153/week @ 2024-03-13 220533/week @ 2024-03-20 208968/week @ 2024-03-27 225808/week @ 2024-04-03 238761/week @ 2024-04-10 229412/week @ 2024-04-17 199540/week @ 2024-04-24 149521/week @ 2024-05-01

853,731 downloads per month
Used in 2,942 crates (56 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
~30K SLoC