Skip to content

Instantly share code, notes, and snippets.

@nijotz nijotz/promises.js
Created Jul 24, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.