I have the following flow of methods
EDIT: where the last methods returns a promise and I want this to propagate back up to the first method in the chain. (I know how to return directly from a promise to a calling function, not sure how it will propagate up the chain?)
function A (input) {
//do something, input = ...
B (input)
.then( (result) => { console.log(result) })
.catch ( (error) => { console.log(error) });
}
function B (intermediate1) {
//do something, intermediate1 = ....
return new Promise ( (resolve, reject) => {
C(intermedediate1)
.then( (result1) => {
//do something to result1
resolve(result1);
})
.catch( (error1) => {
reject(error1);
})
}
}
function C (intermediate2) {
//do something, intermediate2 = ....
return new Promise ( (resolve, reject) => {
D(intermedediate2)
.then( (result) => {
//do something to result
resolve(result);
})
.catch( (error) => {
reject(error);
})
}
}
function D (request) {
return new Promise ( (resolved, reject) => {
//some ASYNC task with request with result and error returned
if (error)
return reject(error);
resolve(result);
}
}
Function A does something to input, call B, which does something more, calls C and so on till D which calls an async method and returns a promise.
I am not sure how to propagate this promise back up the flow to C, B and finally A? I want to do something in each of the methods when I recived the promise back from D and so on.