Any difference between await Promise.all() and multiple await? Any difference between await Promise.all() and multiple await? javascript javascript

Any difference between await Promise.all() and multiple await?


Note:

This answer just covers the timing differences between await in series and Promise.all. Be sure to read @mikep's comprehensive answer that also covers the more important differences in error handling.


For the purposes of this answer I will be using some example methods:

  • res(ms) is a function that takes an integer of milliseconds and returns a promise that resolves after that many milliseconds.
  • rej(ms) is a function that takes an integer of milliseconds and returns a promise that rejects after that many milliseconds.

Calling res starts the timer. Using Promise.all to wait for a handful of delays will resolve after all the delays have finished, but remember they execute at the same time:

Example #1
const data = await Promise.all([res(3000), res(2000), res(1000)])//                              ^^^^^^^^^  ^^^^^^^^^  ^^^^^^^^^//                               delay 1    delay 2    delay 3//// ms ------1---------2---------3// =============================O delay 1// ===================O           delay 2// =========O                     delay 3//// =============================O Promise.all