From: Jérôme Benoit Date: Sat, 3 Jun 2023 21:23:46 +0000 (+0200) Subject: Use promise in busy wait benchmarks X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=1652efb20374a32520ca0713ef0d7ea172293e82;p=benchmarks-js.git Use promise in busy wait benchmarks Signed-off-by: Jérôme Benoit --- 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(