JavaScriptIntermediate#async#performance

How do you run async calls in parallel with async/await?

Start all the promises first, then await them together with Promise.all. Awaiting inside a loop serialises the requests and multiplies latency.

Example
// slow (sequential)
for (const id of ids) await fetchUser(id);
// fast (parallel)
await Promise.all(ids.map(fetchUser));

Related Questions

1
JavaScriptBeginner#async

What is callback hell and how do you avoid it?

Open
2
JavaScriptIntermediate#dom#events

What is event bubbling, capturing and delegation?

Open
3
JavaScriptIntermediate#dom#events

Difference between stopPropagation and preventDefault?

Open