From fb2aa186b76d23d6731803ef41e7a053124444bd Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 31 Oct 2021 00:39:37 -0700 Subject: [Bun.js] Bun.sleep() lets you synchronously sleep. Thanks @evanwashere --- integration/bunjs-only-snippets/sleep.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 integration/bunjs-only-snippets/sleep.js (limited to 'integration/bunjs-only-snippets/sleep.js') 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"); -- cgit v1.2.3