Skip to content

Commit

Permalink
Added timers/promises. Resolves #21
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSpyder committed Dec 10, 2023
1 parent 7dbe2f3 commit c44e231
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/unreleased/Added-20231211-034512.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: Added
body: Timers.Promises from NodeJS 16
time: 2023-12-11T03:45:12.916076+11:00
custom:
Github Issue: "21"
3 changes: 3 additions & 0 deletions lib/js/src/Timers.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions lib/js/test/atomic/Timers.test.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Timers.res
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ external setInterval: (unit => unit, int) => Timeout.t = "setInterval"
@val external clearImmediate: Immediate.t => unit = "clearImmediate"
@val external clearTimeout: Timeout.t => unit = "clearTimeout"
@val external clearInterval: Timeout.t => unit = "clearInterval"

module Promises = {
@module("node:timers/promises")
external setTimeout: int => Js.Promise.t<unit> = "setTimeout"
@module("node:timers/promises")
external setImmediate: 'a => Js.Promise.t<'a> = "setImmediate"
// setInterval is not a promise, it's an async iterator
// @module("node:timers/promises")
// external setInterval: (int, 'a) => Js.Promise.t<'a> = "setTimeout"
}
12 changes: 12 additions & 0 deletions test/atomic/Timers.test.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
open Zora

zora("Timers (promises)", async t => {
t->test("setTimeout", async t => {
let () = await Timers.Promises.setTimeout(100)
t->ok(true, "")
})
t->test("setImmediate", async t => {
let yes = await Timers.Promises.setImmediate("yes")
t->equal(yes, "yes", "")
})
})

0 comments on commit c44e231

Please sign in to comment.