Cscott has uploaded a new change for review. https://gerrit.wikimedia.org/r/97017
Change subject: Add 'forEachPar' and 'forEachSeq' helpers to promise helper module. ...................................................................... Add 'forEachPar' and 'forEachSeq' helpers to promise helper module. These factor out common patterns. Change-Id: I2d757de38120f41b8ba7178e80888b42cf7e7c7f --- M lib/p.js 1 file changed, 25 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Collection/OfflineContentGenerator/bundler refs/changes/17/97017/1 diff --git a/lib/p.js b/lib/p.js index 2f6544a..1f2a0dc 100644 --- a/lib/p.js +++ b/lib/p.js @@ -28,3 +28,28 @@ }); return deferred.promise; }; + +// Returns a promise for completion after iterating through the given +// array in parallel. The function should return a promise for each element. +// This is like map but we throw away the results. +// If the optional `p` parameter is provided, wait for that to resolve +// before starting to process the array contents. +P.forEachPar = function(a, f, p) { + return (p || when.resolve()).then(function() { + return a; + }).then(function(aResolved) { + return when.all(aResolved.map(f)); + }); +}; + +// Returns a promise for completion after iterating through the given +// array in sequence. The function should return a promise for each element. +// If the optional `p` parameter is provided, wait for that to resolve +// before starting to process the array contents. +P.forEachSeq = function(a, f, p) { + p = p || when.resolve(); + return when.reduce(a, function(curResult, value, index, total) { + /* jshint unused: vars */ + return f.call(null, value, index, null); + }, p); +}; -- To view, visit https://gerrit.wikimedia.org/r/97017 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2d757de38120f41b8ba7178e80888b42cf7e7c7f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Collection/OfflineContentGenerator/bundler Gerrit-Branch: master Gerrit-Owner: Cscott <canan...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits