From bcd364e02f04150362bd573ff124c1c6426b7718 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 1 Oct 2023 11:27:17 +0200 Subject: [PATCH] refactor: cleanup promise implementation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- busy-wait.mjs | 4 ++-- promise-handling.mjs | 11 ++--------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/busy-wait.mjs b/busy-wait.mjs index 578e90c..5a55ef8 100644 --- a/busy-wait.mjs +++ b/busy-wait.mjs @@ -45,14 +45,14 @@ async function divideAndConquerTimeoutBusyWait ( * @param intervalMs */ async function setIntervalTimeoutBusyWait (timeoutMs, intervalMs = interval) { - return await new Promise(resolve => { + await new Promise(resolve => { const tries = Math.round(timeoutMs / intervalMs) let count = 0 const triesSetInterval = setInterval(() => { count++ if (count === tries) { clearInterval(triesSetInterval) - return resolve() + resolve() } }, intervalMs) }) diff --git a/promise-handling.mjs b/promise-handling.mjs index 97117f1..7f450b3 100644 --- a/promise-handling.mjs +++ b/promise-handling.mjs @@ -3,19 +3,12 @@ import Benchmark from 'benny' /** * */ -async function promise () { - return await new Promise(resolve => { +async function asyncFunction () { + await new Promise(resolve => { resolve() }) } -/** - * - */ -async function asyncFunction () { - return await promise() -} - Benchmark.suite( 'Promise handling', Benchmark.add('await promise', async () => { -- 2.34.1