Skip to content

Instantly share code, notes, and snippets.

@Kannndev
Created October 4, 2020 10:31
Show Gist options
  • Save Kannndev/3b99280b447a19a549ffc048ebebb1f5 to your computer and use it in GitHub Desktop.
Save Kannndev/3b99280b447a19a549ffc048ebebb1f5 to your computer and use it in GitHub Desktop.
Medium Promise-Bonus tip example
const dog = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('🐶');
console.log('I am still executing!!');
}, 1000);
})
const cat = new Promise((resolve, reject) => {
setTimeout(() => {
reject('🐈');
console.log('Even I am!!');
}, 2000)
})
Promise.all([dog, cat]).then((values) => {
console.log(values)
}).catch((error) => {
console.log('error =>',error);
})
/*
Console Output:
I am still executing!!
Even I am!!
error => 🐈
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment