Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kaidiren/f247ca8fb54afa187bbe71171f5c89b5 to your computer and use it in GitHub Desktop.
Save kaidiren/f247ca8fb54afa187bbe71171f5c89b5 to your computer and use it in GitHub Desktop.
Wait until all ES6 promises complete, even rejected promises
// 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