Skip to content

Instantly share code, notes, and snippets.

@pritidesai
Last active November 3, 2020 07:32
Show Gist options
  • Save pritidesai/452eaa373e00b4013bcf771280d97aa1 to your computer and use it in GitHub Desktop.
Save pritidesai/452eaa373e00b4013bcf771280d97aa1 to your computer and use it in GitHub Desktop.
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');
});
@pritidesai
Copy link
Author

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

@pritidesai
Copy link
Author

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