Skip to content

Instantly share code, notes, and snippets.

@nijotz
Created July 24, 2019 19:48
Show Gist options
  • Save nijotz/7f913c8d7ce5f2d965b7d282080ea272 to your computer and use it in GitHub Desktop.
Save nijotz/7f913c8d7ce5f2d965b7d282080ea272 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 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