Created
August 13, 2018 18:46
-
-
Save srdjanRakic/e615d6ed032c3c7c551feff6f46f7b1c to your computer and use it in GitHub Desktop.
Sync up multiple Promises to a single result set
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
fetchData = () => { | |
const urls = [ | |
"https://jsonplaceholder.typicode.com/posts/1", | |
"https://jsonplaceholder.typicode.com/posts/2", | |
"https://jsonplaceholder.typicode.com/posts/3", | |
"https://jsonplaceholder.typicode.com/posts/4", | |
"https://jsonplaceholder.typicode.com/posts/5", | |
"https://jsonplaceholder.typicode.com/posts/6", | |
"https://jsonplaceholder.typicode.com/posts/7", | |
"https://jsonplaceholder.typicode.com/posts/8" | |
]; | |
const allRequests = urls.map(url => | |
fetch(url).then(response => response.json()) | |
); | |
return Promise.all(allRequests); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment