8 releases

0.2.6 Jan 21, 2023
0.2.5 Nov 29, 2022
0.2.4 Apr 13, 2022
0.2.3 Jan 28, 2022
0.1.0 Sep 13, 2019

#700 in WebAssembly

Download history 71977/week @ 2022-12-01 76338/week @ 2022-12-08 74685/week @ 2022-12-15 45173/week @ 2022-12-22 45017/week @ 2022-12-29 69415/week @ 2023-01-05 67952/week @ 2023-01-12 77652/week @ 2023-01-19 84717/week @ 2023-01-26 83198/week @ 2023-02-02 87017/week @ 2023-02-09 89804/week @ 2023-02-16 91945/week @ 2023-02-23 88962/week @ 2023-03-02 99284/week @ 2023-03-09 102464/week @ 2023-03-16

400,559 downloads per month
Used in 2,070 crates (25 directly)

MIT/Apache

16KB
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.3–2MB
~39K SLoC