Skip to content

Instantly share code, notes, and snippets.

@nijotz
Last active July 24, 2019 20:06
Show Gist options
  • Save nijotz/cd1049116c1a00667993fac69ba9a8c7 to your computer and use it in GitHub Desktop.
Save nijotz/cd1049116c1a00667993fac69ba9a8c7 to your computer and use it in GitHub Desktop.
function sleepReject(time, msg) {
return new Promise((resolve, reject) => {
setTimeout(() => reject(msg || 'reject'), time);
});
}
async function test() {
try {
let valuePromises1 = [1000, 2000, 3000].map(x => sleepReject(x));
let valuePromises2 = [4000, 5000].map(x => sleepReject(x));
let values1 = await Promise.all(valuePromises1);
let values2 = await Promise.all(valuePromises2);
console.log(values1);
console.log(values2);
} catch (error) {
console.log(error);
}
}
test()
// node promises.js
// UnhandledPromiseRejections EVERYWHERE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment