Skip to content

Instantly share code, notes, and snippets.

@artisonian
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artisonian/2508ea3e9d2bb600268e to your computer and use it in GitHub Desktop.
Save artisonian/2508ea3e9d2bb600268e to your computer and use it in GitHub Desktop.
Promise.all for parallel; this for series
'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