mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
feture: promise.mapSeries
This commit is contained in:
+21
-5
@@ -6,14 +6,30 @@ const Promise = require('any-promise');
|
||||
* @param {Array} iteratee returns a new promise.
|
||||
* The iteratee is invoked with three arguments: (value, index, iterable).
|
||||
*/
|
||||
function someSeries(iterable, iteratee) {
|
||||
function anySeries(iterable, iteratee) {
|
||||
var ret = Promise.reject(new Error('init'));
|
||||
iterable.forEach(function(item, idx) {
|
||||
ret = ret
|
||||
.then(x => x)
|
||||
.catch(e => iteratee(item, idx, iterable));
|
||||
ret = ret.catch(e => iteratee(item, idx, iterable));
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
exports.someSeries = someSeries;
|
||||
/*
|
||||
* Call functions in serial until someone rejected.
|
||||
* @param {Array} iterable the array to iterate with.
|
||||
* @param {Array} iteratee returns a new promise.
|
||||
* The iteratee is invoked with three arguments: (value, index, iterable).
|
||||
*/
|
||||
function mapSeries(iterable, iteratee) {
|
||||
var ret = Promise.resolve('init');
|
||||
var result = [];
|
||||
iterable.forEach(function(item, idx) {
|
||||
ret = ret
|
||||
.then(() => iteratee(item, idx, iterable))
|
||||
.then(x => result.push(x));
|
||||
});
|
||||
return ret.then(() => result);
|
||||
}
|
||||
|
||||
exports.anySeries = anySeries;
|
||||
exports.mapSeries = mapSeries;
|
||||
|
||||
Reference in New Issue
Block a user