promise-map-series
Advanced tools
Comparing version 0.2.0 to 0.2.1
# master | ||
# 0.2.1 | ||
* Improve performance | ||
# 0.2.0 | ||
@@ -4,0 +8,0 @@ |
29
index.js
@@ -1,17 +0,16 @@ | ||
var RSVP = require('rsvp') | ||
var Promise = require('rsvp').Promise; | ||
module.exports = function promiseMapSeries (array, iterator, thisArg) { | ||
var results = new Array(array.length) | ||
var index = 0 | ||
return array.reduce(function (promise, item) { | ||
return promise.then(function () { | ||
return iterator.call(thisArg, item, index, array) | ||
}) | ||
.then(function (result) { | ||
results[index++] = result | ||
}) | ||
}, RSVP.resolve()) | ||
.then(function () { | ||
return results | ||
}) | ||
module.exports = function sequence(array, iterator, thisArg) { | ||
var length = array.length | ||
var current = Promise.resolve() | ||
var results = new Array(length) | ||
var cb = arguments.length > 2 ? iterator.bind(thisArg) : iterator | ||
for (var i = 0; i < length; ++i) { | ||
current = results[i] = current.then(function(i) { | ||
return cb(array[i], i, array) | ||
}.bind(undefined, i)) | ||
} | ||
return Promise.all(results) | ||
} |
{ | ||
"name": "promise-map-series", | ||
"description": "Map over array avoiding parallel execution, using promises", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"author": "Jo Liss <joliss42@gmail.com>", | ||
@@ -13,3 +13,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"rsvp": "^3.0.6" | ||
"rsvp": "^3.0.14" | ||
}, | ||
@@ -16,0 +16,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5685
68
Updatedrsvp@^3.0.14