Last active
June 6, 2019 14:31
-
-
Save stenno/090b0bef0dfb986ca1e9ad171a8d5a88 to your computer and use it in GitHub Desktop.
for-of vs. reduce for sequential promises
This file contains hidden or 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 urls = ['foo', 'bar','baz']; | |
// for-of | |
for (const url of urls) { | |
const result = await fetch(url); | |
console.log(result); | |
} | |
// reduce | |
urls.reduce((chain, url) => chain.then(fetch(url)), Promise.resolve()).forEach(result => console.log(result)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment