Last active
April 11, 2019 05:08
-
-
Save srebalaji/33dec6051fa03675ef91233a401a6a2f to your computer and use it in GitHub Desktop.
A sample promise all to handle rejections
This file contains hidden or 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
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