aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-09-17 00:04:13 +0100
committerMichael Williamson <mike@zwobble.org>2026-09-17 00:04:13 +0100
commit61762f3078f0c4aa822f8ad469746f51eb5b6165 (patch)
tree49866cbe0edbaac39848058ece3a93f82bfa66aa
parent1f6838d2c37acd15331f56b80bdd09ac0aae2405 (diff)
Implement forEachSeries() in promises module
-rw-r--r--lib/promises.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/promises.js b/lib/promises.js
index f008200..0da48bb 100644
--- a/lib/promises.js
+++ b/lib/promises.js
@@ -7,8 +7,23 @@ exports.resolve = bluebird.resolve;
exports.reject = bluebird.reject;
exports.forEachSeries = function(array, func) {
- return bluebird.mapSeries(array, func).then(function() {
- });
+ var arrayIndex = 0;
+
+ var deferred = defer();
+
+ var next = function() {
+ if (arrayIndex < array.length) {
+ var element = array[arrayIndex];
+ arrayIndex++;
+ func(element).then(next, deferred.reject);
+ } else {
+ deferred.resolve();
+ }
+ };
+
+ next();
+
+ return deferred.promise;
};
var props = exports.props = function(obj) {