Last active
October 6, 2016 03:36
-
-
Save ccnokes/602fa81d903d1d767dfb151f280c7208 to your computer and use it in GitHub Desktop.
Async series with reduce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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