Last active
July 24, 2019 20:06
-
-
Save nijotz/cd1049116c1a00667993fac69ba9a8c7 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
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