I have written about a half a dozen functions in nodejs using promises, i want really post all of that code, instead i will post a simulated example , so i can encapsulate my problem succinctly. so say i have 2 functions below:
foo = () => {
return new Promise( ( r , rj ) => {
setTimeout( () => {
r('DONE');
}, 3000 );
});
}
And
bar = () => {
return new Promise( (r , rj) => { r('ALL DONE !') } )
}
Now i would like to avoid the callback hell and do the following:
foo().then( (resp) => console.log(resp) ).bar()
Instead what i am forced to do is this:
foo().then( (resp) => { console.log(resp); bar() } )
So basically in my production code i have something like the below, so far(just to give you an idea):
let uploadToVault = ( INPUT_DIR , VOLT_CRED ) => {
INPUT_DIRECTORY = INPUT_DIR;
VOLT_CREDENTIALS = VOLT_CRED;
volt_APILogin().then( () => {
volt_getProduct().then( () => {
volt_CreatePresentation().then( (resp) => {
console.log(resp);
volt_uploadSlides().then( (resp) => {
console.log(resp);
volt_bindSlide().then( (resp) => {
console.log(resp);
});
});
});
});
});
}
Now how can i write this in more a chain format vs writing this in a callback ?