, @jfriend00, , , promises, Promise.all .map.
promises, reduce . Promise.all , . , , , , - .
, reduce, scan (, map) :
Array.prototype.scan = function scanArray(callback, accumulator) {
"use strict";
if (this == null) throw new TypeError('Array::scan called on null or undefined');
if (typeof callback !== 'function') throw new TypeError(callback+' is not a function');
var arr = Object(this),
len = arr.length >>> 0,
res = [];
for (var k = 0; k < len; k++)
if (k in arr)
res[k] = accumulator = callback(accumulator, arr[k], k, arr);
return res;
};
Promise.all(someArray.scan(function(p, item) {
return p.then(function() {
return someFunction(item);
});
}, Promise.resolve())).then(โฆ)
( jQuery Promise.resolve $.Deferred().resolve() Promise.all $.when.apply($, โฆ))