Promise.all

all — A new Promise for when all Promises are resolved or one is rejected without its own catch.

Description

Promise.all(iterable promises)

Parameters

Name Description Type Default Optional
promises An array of promises. iterable No

Return values

A new Promise that resovles when all promises in the input array are completed.

Changelog

Version Description
ES 6 Introduced.

Examples

Example #1 – Promise.all example
let mypromise1 = new Promise(resolve => { resolve('resolved promise 1! :)'); }); let mypromise2 = new Promise((resolve, reject) => { resolve('resolved promise 2! :)'); }); Promise.all([mypromise1, mypromise2]).then(result => { console.log(result); });
Example #2 – Promise.all rejection example

Example showing Promise.all rejecting immediately when one promise rejects without its own catch method. The caught rejection will be the first of the promises that was rejected.

let mypromise1 = new Promise(resolve => { setTimeout(() => { resolve('resolved! :)'); }, 200); }); let mypromise2 = new Promise((resolve, reject) => { reject('rejected promise 2 :('); }); let mypromise3 = new Promise((resolve, reject) => { reject('rejected promise 3 :('); }); Promise.all([mypromise1, mypromise2, mypromise3]).then(result => { console.log(result); }).catch(error => { console.log(error); });
Example #3 – Promise.all rejection example

When a catch method is provided, then Promise.all will also execute the then callback, but with an undefined value for the rejected promise.

let mypromise1 = new Promise(resolve => { setTimeout(() => { resolve('resolved! :)'); }, 500); }); let mypromise2 = new Promise((resolve, reject) => { reject('rejected promise 2 :('); }).catch(error => { console.log(error); }); let mypromise3 = new Promise(resolve => { resolve('resolved! :)'); }); let mypromise4 = new Promise((resolve, reject) => { reject('rejected promise 4 :('); }).catch(error => { console.log(error); }); Promise.all([mypromise1, mypromise2, mypromise3, mypromise4]).then(result => { console.log(result); });

External references