Skip to content

Instantly share code, notes, and snippets.

@arinaldi
Last active October 11, 2018 17:12
Show Gist options
  • Save arinaldi/7fbdd993d5a5845be876e7ef5a0d9cc2 to your computer and use it in GitHub Desktop.
Save arinaldi/7fbdd993d5a5845be876e7ef5a0d9cc2 to your computer and use it in GitHub Desktop.
Async/await with multiple promises
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