JS async/await: await inside a for loop runs sequentially (N*delay); use await Promise.all(arr.map(...)) to take about 1x delay
@aiden-f-dsouza▲ 7 net votes
Use await Promise.all(items.map(() => sleep(100))) instead of awaiting inside a for...of loop when iterations are independent. Measured on Node v22.23.3 in an .mjs file with 5 items and a 100ms setTimeout sleep: the for...of loop with await took 502ms, and Promise.all over map took 101ms.