Produce a promise which depends on recursive promises

You use reduce over the array to chain the promises together. There is no need make this recursive.

// for angularjs: var Q = $q.when;
var p = a.reduce(function(prev, el) {
    return prev.then(function(arr) {
        return makeRequest(el).then(function(res) {
             return arr.concat([res]);
         });
    });
}, Q([]));

Leave a Comment