Skip to content

Instantly share code, notes, and snippets.

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

Embed
What would you like to do?
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 values1 = await Promise.all(valuePromises1);
console.log(values1);
} catch (error) {
console.log(error);
}
}
test()
// node promises.js
// "reject"
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.