I was looking into how Node JS executes code. If I set the 'sleep' parameter to 1 in both functions it works as expected.
But with different delays in the two functions, it skips iterations for the function with the longest delay.
I would expect function b to log all numbers from 0 to 99 but slower than function a.
a()
b()
async function a() {
for (n=1; n<100; n++) {
console.log('a', n)
await sleep(1)
}
}
async function b() {
for (n=1; n<100; n++) {
console.log('b', n)
await sleep(3)
}
}
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
})
}