/**
* @param timeoutMs
+ * @param intervalMs
*/
-async function sleepTimeoutBusyWait (timeoutMs) {
+async function sleepTimeoutBusyWait (timeoutMs, intervalMs = interval) {
const timeoutTimestampMs = Date.now() + timeoutMs
do {
- await sleep(interval)
+ await sleep(intervalMs)
} while (Date.now() < timeoutTimestampMs)
}
* @param timeoutMs
* @param intervalMs
*/
-function setIntervalTimeoutBusyWait (timeoutMs, intervalMs = interval) {
+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)
}
Benchmark.add('divideAndConquerTimeoutBusyWait', async () => {
await divideAndConquerTimeoutBusyWait(timeout)
}),
- Benchmark.add('setIntervalTimeoutBusyWait', () => {
- setIntervalTimeoutBusyWait(timeout)
+ Benchmark.add('setIntervalTimeoutBusyWait', async () => {
+ await setIntervalTimeoutBusyWait(timeout)
}),
Benchmark.cycle(),
Benchmark.complete(),