Skip to content

Instantly share code, notes, and snippets.

@bjangid20
Created June 15, 2021 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjangid20/255f8fc5106651c25c30f392de6692d6 to your computer and use it in GitHub Desktop.
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)
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