combining promises

PHOTO EMBED

Fri Sep 04 2020 05:58:48 GMT+0000 (Coordinated Universal Time)

Saved by @vrzi #javascript

Promise
  .all([ p1, p2, p3 ])
  .then(([ v1, v2, v3 ]) => {
    // Values always correspond to the order of promises,
    // not the order they resolved in (i.e. v1 corresponds to p1)
  });

Promise
  .race([ p1, p2, p3 ])
  .then(val => {
    // val will take the value of the first resolved promise
  });
  
 // Promise.all() turns an array of promises into a promise of an array.
 // If any promise is rejected, the error will pass through.
 // Promise.race() passes throuh the first settled promise.
content_copyCOPY

https://www.30secondsofcode.org/blog/s/async-javascript-cheatsheet