1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! WebAssembly implementation of the platform primitives.
//!
//! Timers are driven as futures on the browser event loop:
//! [`wasm_bindgen_futures::spawn_local`] owns each task and
//! [`gloo_timers::future::sleep`] (backed by `setTimeout`) provides the delay.
//! Because the executor owns and drops the future when it completes, there is
//! no per-tick closure leak and no closure is ever dropped from inside its own
//! callback — the two hazards of the raw `setInterval` callback API.
//!
//! Monotonic time comes from `performance.now()` (through `web-time`). There
//! are no OS threads, so the `precise` flag on [`spawn_interval`] is ignored
//! (`setTimeout` is millisecond-resolution and subject to browser throttling)
//! and [`par_for_each`] runs sequentially.
use Duration;
use sleep;
use spawn_local;
pub use Instant;
/// Run `f` once after `delay`, as a task on the browser event loop.
///
/// The task is owned by the executor and freed once `f` runs — no leak.
/// Cancellation is the caller's responsibility (operators use a weak upgrade /
/// generation check inside `f`).
/// Repeatedly invoke `tick(count)` every `period`, with `count` beginning at 1.
/// The task ends (and stops re-arming the timer) when `tick` returns `false`.
///
/// `precise` is ignored on wasm — there is no sub-millisecond timer available
/// in the browser.
/// Fan out `f` across `items`. wasm is single-threaded, so this runs
/// sequentially — the API matches the native rayon fan-out.