Created
July 24, 2019 19:10
-
-
Save nijotz/b456005e1b72a04cac6e5a45694fd43c to your computer and use it in GitHub Desktop.
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
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