Skip to content

Instantly share code, notes, and snippets.

@srebalaji
Last active April 11, 2019 05:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srebalaji/33dec6051fa03675ef91233a401a6a2f to your computer and use it in GitHub Desktop.
Save srebalaji/33dec6051fa03675ef91233a401a6a2f to your computer and use it in GitHub Desktop.
A sample promise all to handle rejections
const durations = [1000, 2000, 3000]
promises = durations.map((duration) => {
return timeOut(duration).catch(e => e) // Handling the error for each promise.
})
Promise.all(promises)
.then(response => console.log(response)) // ["Completed in 1000", "Rejected in 2000", "Completed in 3000"]
.catch(error => console.log(`Error in executing ${error}`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment