I have following code:
fetchAsync().then()
async function fetchAsync() {
return await Promise.all([...Array(1000).keys()].map((i) => wait(i)))
}
async function wait(i) {
const startTime = Date.now();
await new Promise(resolve => {
setTimeout(() => resolve(), 100)
});
const timePassed = Date.now() - startTime;
console.log(`Call ${i}: ${timePassed}ms`)
}
Console output is
Call 0: 102ms
Call 1: 108ms
Call 2: 109ms
Call 3: 109ms
Call 4: 109ms
Call 5: 110ms
...
Call 995: 190ms
Call 996: 190ms
Call 997: 190ms
Call 998: 190ms
Call 999: 190ms
As you can see, the execution time of wait is increasing every time its being executed. Does anyone know why this is happening?