Created
June 2, 2017 12:35
-
-
Save kaidiren/f247ca8fb54afa187bbe71171f5c89b5 to your computer and use it in GitHub Desktop.
Wait until all ES6 promises complete, even rejected promises
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
// https://stackoverflow.com/questions/31424561/wait-until-all-es6-promises-complete-even-rejected-promises/36115549#36115549 | |
var a = () => Promise.resolve(1); | |
var b = () => Promise.reject(new Error(2)); | |
var c = () => Promise.resolve(3); | |
Promise.all([a(), b(), c()].map(p => p.catch(e => e))) | |
.then(results => console.log(results)) // 1,Error: 2,3 | |
.catch(e => console.log(e)); | |
var console = { log: msg => div.innerHTML += msg + "<br>"}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment