Last active
November 3, 2020 07:32
-
-
Save pritidesai/452eaa373e00b4013bcf771280d97aa1 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
new Promise((resolve, reject) => { | |
let a = 50 / 2 // Task A | |
resolve(a) | |
}).then((result) => { | |
console.log('In TaskB - TaskA finished with result', result); // Task B | |
}).finally((result) => { // list of finally tasks | |
console.log('In finally - TaskA finished with result', result); | |
console.log('Continue running rest of the finally tasks'); | |
}); | |
const taskA = new Promise((resolve, reject) => {
if (1 == 1) { // Task Validation
resolve('Success');
} else {
reject('Failed');
}
}).then((result) => {
console.log('Step1');
return result;
}).then((result) => {
console.log('Step2');
return result;
}).catch((result) => {
console.log('Task Validation Failed');
}).finally(() => {
console.log('finally tasks');
});
const taskB = new Promise((resolve, reject) => {
resolve('TaskB')
})
const taskC = new Promise((resolve, reject) => {
resolve('TaskC')
})
Promise.all([
taskA,
taskB,
taskC
]).then((values) => {
console.log(values);
}).catch((error) => {
console.error(error.message)
}).finally(() => {
console.log('finally tasks');
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
=>