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

#274 in WebAssembly

Download history 271054/week @ 2024-10-24 280620/week @ 2024-10-31 409472/week @ 2024-11-07 398267/week @ 2024-11-14 352727/week @ 2024-11-21 294992/week @ 2024-11-28 391437/week @ 2024-12-05 389129/week @ 2024-12-12 218009/week @ 2024-12-19 132736/week @ 2024-12-26 338133/week @ 2025-01-02 445351/week @ 2025-01-09 383876/week @ 2025-01-16 404933/week @ 2025-01-23 432559/week @ 2025-01-30 473902/week @ 2025-02-06

1,783,056 downloads per month
Used in 3,445 crates (73 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
~29K SLoC