gloo-timers

Crates.iogloo-timers
lib.rsgloo-timers
version0.3.0
sourcesrc
created_at2019-09-13 11:49:44.838113
updated_at2023-08-11 16:04:38.773701
descriptionConvenience crate for working with JavaScript timers
homepagehttps://github.com/rustwasm/gloo
repositoryhttps://github.com/rustwasm/gloo/tree/master/crates/timers
max_upload_size
id164548
size22,125
Elina (ranile)

documentation

README

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.

Commit count: 376

cargo fmt