summaryrefslogtreecommitdiff
path: root/doc/Timers.md
blob: 28008b030ae17c9e4d561c0b4ade50657b029ec2 (plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Timers

GJS implements the [WHATWG Timers][whatwg-timers] specification, with some
changes to accommodate the GLib event loop.

In particular, the returned value of `setInterval()` and `setTimeout()` is not a
`Number`, but a [`GLib.Source`][gsource].

#### Import

The functions in this module are available globally, without import.

[whatwg-timers]: https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timers
[gsource]: https://gjs-docs.gnome.org/glib20/glib.source

### setInterval(handler, timeout, ...arguments)

Type:
* Static

Parameters:
* handler (`Function`) — The callback to invoke
* timeout (`Number`) — Optional interval in milliseconds
* arguments (`Array(Any)`) — Optional arguments to pass to `handler`

Returns:
* (`GLib.Source`) — The identifier of the repeated action

> New in GJS 1.72 (GNOME 42)

Schedules a timeout to run `handler` every `timeout` milliseconds. Any
`arguments` are passed straight through to the `handler`.

### clearInterval(id)

Type:
* Static

Parameters:
* id (`GLib.Source`) — The identifier of the interval you want to cancel.

> New in GJS 1.72 (GNOME 42)

Cancels the timeout set with `setInterval()` or `setTimeout()` identified by
`id`.

### setTimeout(handler, timeout, ...arguments)

Type:
* Static

Parameters:
* handler (`Function`) — The callback to invoke
* timeout (`Number`) — Optional timeout in milliseconds
* arguments (`Array(Any)`) — Optional arguments to pass to `handler`

Returns:
* (`GLib.Source`) — The identifier of the repeated action

> New in GJS 1.72 (GNOME 42)

Schedules a timeout to run `handler` after `timeout` milliseconds. Any
`arguments` are passed straight through to the `handler`.

### clearTimeout(id)

Type:
* Static

Parameters:
* id (`GLib.Source`) — The identifier of the timeout you want to cancel.

> New in GJS 1.72 (GNOME 42)

Cancels the timeout set with `setTimeout()` or `setInterval()` identified by
`id`.