X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=busy-wait.js;h=a851a30e911870542cd9612b2777c7654c057a36;hb=38acce1ce538dd398196b8ab7834d55938d4fde7;hp=9c392a53c06755d1e1d3f321f9c6ae176d14d3b5;hpb=41672b128b0270f3f6c72a8ed3d69d0bea0ad366;p=benchmarks-js.git diff --git a/busy-wait.js b/busy-wait.js index 9c392a5..a851a30 100644 --- a/busy-wait.js +++ b/busy-wait.js @@ -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) +})