Last active
August 29, 2015 14:05
-
-
Save artisonian/2508ea3e9d2bb600268e to your computer and use it in GitHub Desktop.
Promise.all for parallel; this for series
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var Promise = require('es6-promise'); | |
// See http://www.html5rocks.com/en/tutorials/es6/promises/ | |
module.exports = function sequencePromises (promises, transformFn) { | |
function identity (x) { return x; } | |
return promises.reduce(function (sequence, promise) { | |
return sequence.then(function () { | |
return promise; | |
}).then((typeof transformFn === 'function') ? transformFn : identity); | |
}, Promise.resolve()); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment