top | item 39891629

(no title)

3m | 1 year ago

Doing multiple async tasks concurrently as opposed to in sequence. If you have never used this you have either worked on extremely simple systems or have been leaving a ton of perf gains on the table.

discuss

order

Capricorn2481|1 year ago

Or, like most people, they don't work with JS outside of the frontend where fetching multiple things in parallel is rarely needed.

recursive|1 year ago

How is this different from await a, await b, await c?

jonathanlydall|1 year ago

If each await was to a setTimeout call waiting 1000ms, awaiting all 3 would take approximately 3000ms.

If you await a Promise.all with an array of the promises, it will take approximately 1000ms.

In summary, using individual awaits runs them serially, while Promise.all runs them concurrently.

If you’re doing CPU bound work without workers, it doesn’t make much of a difference, but if you’re doing I/O bound tasks, like HTTP requests, then doing it in parallel will likely make a significant difference.