Created
April 19, 2020 11:51
-
-
Save neuralline/2d1ed30a25e33e3395f603b2946125e1 to your computer and use it in GitHub Desktop.
async await for loop
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
//async for loop | |
//Why ? performance also browser support | |
const getGitHubUser = async (usernames: []) => { | |
//const results:[]:=[] //<-results array here | |
const length = usernames.length | |
for (let i = 0; i < length; i++) { | |
try { | |
const response = await fetch( | |
`https://api.github.com/users/${usernames[i]}` | |
) | |
const data = await response.json() | |
return data // results.push(data) //<-push to results array or call-back user(data) | |
} catch (err) { | |
console.error(`I'm down, this time. ${err}`) | |
} | |
} | |
return //await results | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment