10 releases

0.4.0 Mar 25, 2026
0.3.0 Aug 11, 2023
0.2.6 Jan 21, 2023
0.2.5 Nov 29, 2022
0.1.0 Sep 13, 2019

#25 in WebAssembly

Download history 1062500/week @ 2026-01-17 1083966/week @ 2026-01-24 1102986/week @ 2026-01-31 1131314/week @ 2026-02-07 1047667/week @ 2026-02-14 1203251/week @ 2026-02-21 1452463/week @ 2026-02-28 1447997/week @ 2026-03-07 1273758/week @ 2026-03-14 1133445/week @ 2026-03-21 1075309/week @ 2026-03-28 1089324/week @ 2026-04-04 1158949/week @ 2026-04-11 1082802/week @ 2026-04-18 1146215/week @ 2026-04-25 1246886/week @ 2026-05-02

4,832,050 downloads per month
Used in 4,432 crates (224 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.7MB
~28K SLoC