Promise.all is one among potentially many Promise combinators someone may wish to use with an array of Promises. (Promise.race is another. There are others, especially as you expand out into the Observable space.)
One example for Promise.race might be a Promise to get data from a cache and another from an HTTP call and you don't care which returns the data, you just want whichever is fastest. Your HTTP call might eventually update your cache and "repaint/recalculate" somehow down the line. That HTTP call still might be "faster" than your cache if the cache hasn't been populated yet and is waiting for data to arrive.
5 comments
[ 1.6 ms ] story [ 19.4 ms ] threadIt would've been easier if await just accepted arrays just like how generators in co could use yield on arrays to wait on them all.
Also when do you need to use Promise.race?
One example for Promise.race might be a Promise to get data from a cache and another from an HTTP call and you don't care which returns the data, you just want whichever is fastest. Your HTTP call might eventually update your cache and "repaint/recalculate" somehow down the line. That HTTP call still might be "faster" than your cache if the cache hasn't been populated yet and is waiting for data to arrive.