X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=busy-wait.js;fp=busy-wait.js;h=3316db96bedab3163f0f7b2c4e18a1b54096cb8d;hb=1652efb20374a32520ca0713ef0d7ea172293e82;hp=9c392a53c06755d1e1d3f321f9c6ae176d14d3b5;hpb=104e3c1436486cc4a68e679fc5f738b8ea85bc4a;p=benchmarks-js.git diff --git a/busy-wait.js b/busy-wait.js index 9c392a5..3316db9 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(