UNPKG

@mightyplow/jslib

Version:

js helpers library

32 lines (29 loc) 1.06 kB
/** Returns a function which executes promises one after another. The resulting function returns a promise, which gets filled with an array of the results of the single promises. @memberOf function @param promiseGenerators an array of functions which return a promise @return function which executes the promises */ var enqueueWithResults = function () { var fnQueue = function fnQueue(results, promiseGenerators) { return promiseGenerators.reduce(function (f, promiseGenerator) { return function () { return f().then(function (result) { results.push(result); return promiseGenerator(); }); }; }); }; return function (promiseGenerators) { return function () { var results = []; return fnQueue(results, promiseGenerators)().then(function (result) { results.push(result); return results; }); }; }; }(); export default enqueueWithResults;