Created
October 20, 2018 19:40
-
-
Save syzer/8df4e0753bcf7305b49ae49e5f9b7f20 to your computer and use it in GitHub Desktop.
Use reduce for serial async resolution AKA map.series
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
const asyncFunction = (nextID) => | |
new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log(`Called with ${new Date()}`) | |
resolve() | |
}, 1000) | |
}) | |
;[1, 2, 3].reduce((accumulatorPromise, nextID) => { | |
console.log(`Looped with ${new Date()}`) | |
return accumulatorPromise | |
.then(() => | |
asyncFunction(nextID)) | |
}, Promise.resolve()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment