I can't figure out why the following function is running so quickly, the bottom level async function is running in 0.06 seconds instead of my expected 2.06 seconds (after the sleep function).
const hiWorld = () => {
const final = await Promise.all(
firstLevelArray.map(async (secondLevelArray) => {
const topLevelResponse = await Promise.all(
secondLevelArray.map(async (item) => {
const asyncResponse = await myAsyncFunction({
item: item,
});
console.log(new Date()) // this shows that it's running within .06 seconds instead of 2.06 seconds
await new Promise(r => setTimeout(r, 2000));
return asyncResponse
})
);
return topLevelResponse
})
);
return final
}
In case it's important, this is with Typescript.
Here's the console.log:
2021-04-07T01:45:02.501Z
2021-04-07T01:45:02.552Z
2021-04-07T01:45:02.619Z