Skip to content

Instantly share code, notes, and snippets.

@ccnokes
Last active October 6, 2016 03:36
Show Gist options
  • Save ccnokes/602fa81d903d1d767dfb151f280c7208 to your computer and use it in GitHub Desktop.
Save ccnokes/602fa81d903d1d767dfb151f280c7208 to your computer and use it in GitHub Desktop.
Async series with reduce
function asyncThing() {
return new Promise(res => {
setTimeout(() => {
res(Math.random());
}, 1000);
});
}
function series(...promises) {
return promises.reduce((p, fn) => p.then(fn), Promise.resolve());
}
series(asyncThing, asyncThing, asyncThing)
.then(result => console.log(result));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment