Skip to content

Instantly share code, notes, and snippets.

@jeremy-brenner
Created March 24, 2017 21:17
Show Gist options
  • Save jeremy-brenner/4e09021870bf6cca8b765ca3162565ce to your computer and use it in GitHub Desktop.
Save jeremy-brenner/4e09021870bf6cca8b765ca3162565ce to your computer and use it in GitHub Desktop.
callback accumulator using reduce
list_of_things.reduce(function(accumulator, link) {
return accumulator.then(function(results) {
return doSomething(link).then(function(result) {
results.push(result);
return results;
});
}), Promise.resolve([])).then(function(results){
console.log('all results', results );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment