Javascript - Collection Promises.all()


Promise.all takes an array of promises or iterable of promises.

It returns a promise that resolves when all of the promises in the iterable argument have resolved, or rejects with the reason of the first passed promise that rejects.

If any of the passed in promises rejects, then all the promises immediately reject with the value of the promise that rejected.

If an empty array is passed, then this method resolves immediately.


const p1 = Promise.resolve(3); 
const p2 = 42; //from www  .ja  v a  2  s. c  o  m
const p3 = new Promise((resolve, reject) => { 
      setTimeout(resolve, 100, "foo"); 

Promise.all([p1, p2, p3]).then(values => { 
       console.log(values); // [3, 42, "foo"] 


Related Topic