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'); | |
}); | |
Author
pritidesai
commented
Oct 30, 2020
•
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
return 100
}).then((result) => {
console.log('In TaskC - TaskB finished with result', result); // Task C
return 200
}).then((result) => {
console.log('In TaskD - TaskC finished with result', result); // Task D
return 300
}).finally((result) => { // list of finally tasks
console.log('In finally - TaskD finished with result', result); // Finally A
console.log('Continues running rest of the finally tasks'); // Finally B
});
=>
In TaskB - TaskA finished with result 25
In TaskC - TaskB finished with result 100
In TaskD - TaskC finished with result 200
In finally - TaskD finished with result undefined
Continues running rest of the finally tasks
new Promise((resolve, reject) => {
// Pipeline Validation
if (1 == 1) {
resolve('Success');
} else {
reject('Failed');
}
}).then((result) => {
console.log('TaskA');
return result;
}).then((result) => {
console.log('TaskB');
return result;
}).then((result) => {
console.log('TaskC');
return result;
}).catch((result) => {
console.log('Pipeline Validation Failed');
}).finally((result) => { // list of finally tasks
console.log('In finally - Task finished with result', result);
console.log('Continue running rest of the finally tasks');
});
=>
TaskA
TaskB
TaskC
In finally - Task finished with result undefined
Continue running rest of the finally tasks
new Promise((resolve, reject) => {
// Pipeline Validation
if (1 == 0) {
resolve('Success');
} else {
reject('Failed');
}
}).then((result) => {
console.log('TaskA');
return result;
}).then((result) => {
console.log('TaskB');
return result;
}).then((result) => {
console.log('TaskC');
return result;
}).catch((result) => {
console.log('Pipeline Validation Failed');
}).finally((result) => { // list of finally tasks
console.log('In finally - Task finished with result', result);
console.log('Continue running rest of the finally tasks');
});
=>
Pipeline Validation Failed
In finally - Task finished with result undefined
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