How to resolve multiple promises

You have more than one promise and you need to wait for all of them to finish up before you can do the next step. Use JavaScript native Promise.all() to consolidate your promises into a single promise. You pass in an array of promises, it’s then value will be an array of values in the same order as the promises they originate from.

Common libraries and their version of Promise.all()

Perhaps you need to support older browsers that don’t support native promises or you already work within an existing framework. Here are the common libraries and frameworks with their version of Promise.all().

jQuery

jQuery has been around so long that it’s promises predate the native specs which means it’s API is the most different of all on this list. jQuery provides a $.when() method to consolidate promises. It varies in that you pass each promise as a parameter instead of as an array, and each value is an argument into the .then() method.

Angular

Angular’s promises module, $q, has a static method of $q.all() to consolidate multiple promises. Just like the native Promise.all(), it takes an array of promises and the then receives an array of values. Additionally, it will take care of running the digest so changes to $scope will take effect.

Dojo

Dojo has a function, dojo/promise/all, to join multiple promises into a single promise. Just like the native Promise.all(), it takes an array of promises and the then receives an array of values.

Bluebird

Bluebird is designed to be a superset of native promises which means the API for creating a promise of promises is the same as native promises.

Q

Q is similar to Bluebird in that it follows the core native promise API and then adds functionality. The API for resolving multiple promises is the same as native promises.