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

#259 in WebAssembly

Download history 205819/week @ 2024-06-24 181071/week @ 2024-07-01 194177/week @ 2024-07-08 200593/week @ 2024-07-15 224911/week @ 2024-07-22 205590/week @ 2024-07-29 210784/week @ 2024-08-05 213655/week @ 2024-08-12 215668/week @ 2024-08-19 225050/week @ 2024-08-26 231667/week @ 2024-09-02 229431/week @ 2024-09-09 223540/week @ 2024-09-16 245794/week @ 2024-09-23 245986/week @ 2024-09-30 259317/week @ 2024-10-07

985,406 downloads per month
Used in 3,206 crates (66 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.9–1.6MB
~30K SLoC