Skip to content

Instantly share code, notes, and snippets.

@reem
Forked from anonymous/all.js
Created November 25, 2015 23:06
Show Gist options
  • Save reem/7736404f5eedfd88902a to your computer and use it in GitHub Desktop.
Save reem/7736404f5eedfd88902a to your computer and use it in GitHub Desktop.
function all(promises) {
return promises.reduce(function (previous, next) {
return join(previous, next, function ([previous_results, next_val]) {
previous_results.push(next_val);
return previous_results;
});
}, Promise.resolve([]));
}
function join(x, y) {
return x.then(function (x_val) {
y.then(function (y_val) {
return [x, y];
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment