Skip to content

Instantly share code, notes, and snippets.

@bluepnume
Last active December 29, 2015 11:59
Show Gist options
  • Save bluepnume/7667586 to your computer and use it in GitHub Desktop.
Save bluepnume/7667586 to your computer and use it in GitHub Desktop.
var q = require('q');
q.sequential = function(promises) {
var results = [];
return promises.reduce(function(aggregate, promise) {
return aggregate.then(function() {
return promise.then(function(result) {
results.push(result);
});
})
}, q()).then(function() {
return results;
})
}
function createNewMerchant() {
return q('mymerchant');
}
function createNewYouthAccount() {
return q('myyouth');
}
q.sequential([createNewMerchant(), createNewYouthAccount()]).spread(function(merchant, youth) {
console.log(merchant, youth);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment