1 import Enumerator from '../enumerator';
4 `Promise.all` accepts an array of promises, and returns a new promise which
5 is fulfilled with an array of fulfillment values for the passed promises, or
6 rejected with the reason of the first passed promise to be rejected. It casts all
7 elements of the passed iterable to promises as it runs this algorithm.
12 let promise1 = resolve(1);
13 let promise2 = resolve(2);
14 let promise3 = resolve(3);
15 let promises = [ promise1, promise2, promise3 ];
17 Promise.all(promises).then(function(array){
18 // The array here would be [ 1, 2, 3 ];
22 If any of the `promises` given to `all` are rejected, the first promise
23 that is rejected will be given as an argument to the returned promises's
24 rejection handler. For example:
29 let promise1 = resolve(1);
30 let promise2 = reject(new Error("2"));
31 let promise3 = reject(new Error("3"));
32 let promises = [ promise1, promise2, promise3 ];
34 Promise.all(promises).then(function(array){
35 // Code here never runs because there are rejected promises!
37 // error.message === "2"
43 @param {Array} entries array of promises
44 @param {String} label optional string for labeling the promise.
46 @return {Promise} promise that is fulfilled when all `promises` have been
47 fulfilled, or rejected if any of them become rejected.
50 export default function all(entries) {
51 return new Enumerator(this, entries).promise;