diff options
author | 2021-10-31 00:39:37 -0700 | |
---|---|---|
committer | 2021-10-31 00:39:37 -0700 | |
commit | fb2aa186b76d23d6731803ef41e7a053124444bd (patch) | |
tree | de8607abccfe4da017a9b3642e9d016604ffa4ea /integration/bunjs-only-snippets/sleep.js | |
parent | ef94826f95ddbd48ad9026966e4106c330c27498 (diff) | |
download | bun-fb2aa186b76d23d6731803ef41e7a053124444bd.tar.gz bun-fb2aa186b76d23d6731803ef41e7a053124444bd.tar.zst bun-fb2aa186b76d23d6731803ef41e7a053124444bd.zip |
[Bun.js] Bun.sleep() lets you synchronously sleep. Thanks @evanwashere
Diffstat (limited to 'integration/bunjs-only-snippets/sleep.js')
-rw-r--r-- | integration/bunjs-only-snippets/sleep.js | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/integration/bunjs-only-snippets/sleep.js b/integration/bunjs-only-snippets/sleep.js new file mode 100644 index 000000000..9a62201c5 --- /dev/null +++ b/integration/bunjs-only-snippets/sleep.js @@ -0,0 +1,10 @@ +const interval = 0.5; +const now = performance.now(); +console.time("Slept"); +Bun.sleep(interval); +const elapsed = performance.now() - now; +if (elapsed < interval) { + throw new Error("Didn't sleep"); +} + +console.timeEnd("Slept"); |