Skip to content

Commit 36cb2d1

Browse files
authored
Merge pull request #88 from julien-deoux/timeout-ergonomics
Improve setTimeout ergonomics
2 parents 161c54b + 8e1fe03 commit 36cb2d1

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/DOMAPI.res

+2
Original file line numberDiff line numberDiff line change
@@ -9917,3 +9917,5 @@ type blobCallback = blob => unit
99179917
type videoFrameRequestCallback = float => videoFrameCallbackMetadata => unit
99189918

99199919
type frameRequestCallback = float => unit
9920+
9921+
type timeoutId

src/DOMAPI/Window.res

+5-7
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,20 @@ external btoa: (window, string) => string = "btoa"
2727
external atob: (window, string) => string = "atob"
2828

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

4137
/**
38+
Cancels the execution of a timeout created with setTimeout.
39+
4240
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/clearTimeout)
4341
*/
4442
@send
45-
external clearTimeout: (window, int) => unit = "clearTimeout"
43+
external clearTimeout: (window, timeoutId) => unit = "clearTimeout"
4644

4745
/**
4846
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/setInterval)

src/Global.res

+5-6
Original file line numberDiff line numberDiff line change
@@ -260,19 +260,18 @@ external btoa: string => string = "btoa"
260260
external atob: string => string = "atob"
261261

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

272269
/**
270+
Cancels the execution of a timeout created with setTimeout.
271+
273272
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/clearTimeout)
274273
*/
275-
external clearTimeout: int => unit = "clearTimeout"
274+
external clearTimeout: timeoutId => unit = "clearTimeout"
276275

277276
/**
278277
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/setInterval)

0 commit comments

Comments
 (0)