Skip to content

Instantly share code, notes, and snippets.

@nijotz
Created July 24, 2019 19:10
Show Gist options
  • Save nijotz/b456005e1b72a04cac6e5a45694fd43c to your computer and use it in GitHub Desktop.
Save nijotz/b456005e1b72a04cac6e5a45694fd43c to your computer and use it in GitHub Desktop.
async function test() {
var p1 = new Promise((resolve, reject) => {
setTimeout(() => reject('one'), 1000);
});
var p2 = new Promise((resolve, reject) => {
setTimeout(() => reject('two'), 2000);
});
var p3 = new Promise((resolve, reject) => {
setTimeout(() => reject('three'), 3000);
});
var p4 = new Promise((resolve, reject) => {
setTimeout(() => reject('four'), 4000);
});
var p5 = new Promise((resolve, reject) => {
reject(new Error('reject'));
});
try {
let values = await Promise.all([p1, p2, p3, p4, p5]);
console.log(values);
} catch (error) {
console.log(error.message);
}
}
test().catch(console.error);
// node promises.js
// "reject"
// *pause*
// (no further errors/output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment