I'm in the process of replacing old code that used jQuery Deferred objects, and I'm rewriting with Bluebird / ES6 Promises.
If I have several asynchronous calls, how can I call the function after all the promises are resolved.
Using jQuery Deferreds, it would be something like this:
var requests = [...]; //some arbitrary data that is iterated to generate multiple ajax requests var promises = []; resuests.forEach(function(endpoint) { promises.push($.ajax({url: endpoint})); }); $.when.apply($, promises).then(function() { alert('all promises complete!'); });
How do I rewrite this using Promise ES6 syntax?
source share