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

#185 in WebAssembly

Download history 326373/week @ 2024-12-01 428635/week @ 2024-12-08 363518/week @ 2024-12-15 135714/week @ 2024-12-22 194834/week @ 2024-12-29 388860/week @ 2025-01-05 450250/week @ 2025-01-12 369356/week @ 2025-01-19 408346/week @ 2025-01-26 456162/week @ 2025-02-02 473007/week @ 2025-02-09 452819/week @ 2025-02-16 502142/week @ 2025-02-23 527115/week @ 2025-03-02 554550/week @ 2025-03-09 535058/week @ 2025-03-16

2,139,731 downloads per month
Used in 3,519 crates (78 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

~0.8–1.6MB
~29K SLoC