Last active
October 11, 2018 17:12
-
-
Save arinaldi/7fbdd993d5a5845be876e7ef5a0d9cc2 to your computer and use it in GitHub Desktop.
Async/await with multiple promises
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 URL = 'https://api.github.com/users/'; | |
const getData = async (usernames) => { | |
const promises = usernames.map(username => fetch(`${URL}${username}`).then(r => r.json())); | |
const userData = await Promise.all(promises); | |
return userData; | |
}; | |
const data = await getData(['arinaldi', 'thomasdtucker']); | |
console.log({ data }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment