Skip to content

Commit 5085d32

Browse files
committed
Improve setTimeout ergonomics
1 parent dd26767 commit 5085d32

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/DOMAPI/Window.res

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,25 @@ external btoa: (window, string) => string = "btoa"
2727
external atob: (window, string) => string = "atob"
2828

2929
/**
30+
Executes a function after a delay given in milliseconds expires.
31+
3032
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/setTimeout)
3133
*/
3234
@send
33-
external setTimeout: (window, ~handler: string, ~timeout: int=?) => int = "setTimeout"
35+
external setTimeout: (window, ~handler: unit => unit, ~timeout: int=?) => int = "setTimeout"
3436

3537
/**
38+
Evaluates and executes raw JavaScript code after a delay given in milliseconds
39+
expires. Use of this function is not recommended.
40+
3641
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/setTimeout)
3742
*/
3843
@send
39-
external setTimeout2: (window, ~handler: unit => unit, ~timeout: int=?) => int = "setTimeout"
44+
external setTimeout_unsafe: (window, ~code: string, ~timeout: int=?) => int = "setTimeout"
4045

4146
/**
47+
Cancels the execution of a timeout created with setTimeout.
48+
4249
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/clearTimeout)
4350
*/
4451
@send

src/Global.res

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,23 @@ external btoa: string => string = "btoa"
260260
external atob: string => string = "atob"
261261

262262
/**
263+
Executes a function after a delay given in milliseconds expires.
264+
263265
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/setTimeout)
264266
*/
265-
external setTimeout: (~handler: string, ~timeout: int=?) => int = "setTimeout"
267+
external setTimeout: (~handler: unit => unit, ~timeout: int=?) => int = "setTimeout"
266268

267269
/**
270+
Evaluates and executes raw JavaScript code after a delay given in milliseconds
271+
expires. Use of this function is not recommended.
272+
268273
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/setTimeout)
269274
*/
270-
external setTimeout2: (~handler: unit => unit, ~timeout: int=?) => int = "setTimeout"
275+
external setTimeout_unsafe: (~code: string, ~timeout: int=?) => int = "setTimeout"
271276

272277
/**
278+
Cancels the execution of a timeout created with setTimeout.
279+
273280
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/clearTimeout)
274281
*/
275282
external clearTimeout: int => unit = "clearTimeout"

0 commit comments

Comments
 (0)