build: bump volta pnpm version
[benchmarks-js.git] / busy-wait.js
index 9c392a53c06755d1e1d3f321f9c6ae176d14d3b5..a851a30e911870542cd9612b2777c7654c057a36 100644 (file)
@@ -45,15 +45,17 @@ async function divideAndConquerTimeoutBusyWait (
  * @param intervalMs
  */
 async function setIntervalTimeoutBusyWait (timeoutMs, intervalMs = interval) {
-  const tries = Math.round(timeoutMs / intervalMs)
-  let count = 0
-  const triesSetInterval = setInterval(() => {
-    count++
-    if (count === tries) {
-      clearInterval(triesSetInterval)
-      return Promise.resolve()
-    }
-  }, intervalMs)
+  return new Promise(resolve => {
+    const tries = Math.round(timeoutMs / intervalMs)
+    let count = 0
+    const triesSetInterval = setInterval(() => {
+      count++
+      if (count === tries) {
+        clearInterval(triesSetInterval)
+        return resolve()
+      }
+    }, intervalMs)
+  })
 }
 
 Benchmark.suite(
@@ -75,4 +77,6 @@ Benchmark.suite(
   Benchmark.save({ file: 'busy-wait', format: 'json', details: true }),
   Benchmark.save({ file: 'busy-wait', format: 'chart.html', details: true }),
   Benchmark.save({ file: 'busy-wait', format: 'table.html', details: true })
-)
+).catch(err => {
+  console.error(err)
+})