Created
June 15, 2021 12:29
-
-
Save bjangid20/255f8fc5106651c25c30f392de6692d6 to your computer and use it in GitHub Desktop.
multiple async call and get result of sucess and failure call both (Don't turminate after a failure)
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
var urls = [ | |
'https://api.github.com/users/iliakan', | |
'https://remy.com', | |
'https://api.github.com/users/jeresig' | |
]; | |
Promise.all( | |
urls.map(url => | |
fetch(url) | |
.then(r => r.json()) | |
.catch(e => e) | |
) | |
) | |
.then(responses => { | |
console.log(responses); | |
}); | |
or you can get only successful results. | |
Promise.all( | |
url.map(url => | |
fetch(url) | |
.then(r => r.json()) | |
.catch(e => '') | |
) | |
) | |
.then(responses => { | |
console.log(responses.filter(Boolean)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment