The following chain is to be executed sequentially
$.when()
.pipe(functionA)
.pipe(functionB)
.fail(functionC);
where functionA returns a Promise.
function functionA() {
return networkCall().then(sideEffectsForSuccess).catch(sideEffectsForFailure);
}
function networkCall() {
return new Promise(function (resolve, reject) {
return $.ajax(...);
});
}
However, this doesn't seem to work, since functionB gets immediately executed without waiting for the Promise returned from functionA to resolve (or fail). The chain works correctly if functionA is changed to
function functionA() {
return $.ajax(...).pipe(sideEffectsForSuccess, sideEffectsForFailure);
}
Unfortunately, I have to use networkCall. Any ideas how to make this work?
Can you return the promise
function functionA() {
let callPromise = networkCall();
callPromise.then(sideEffectsForSuccess).catch(sideEffectsForFailure);
return callPromise;
}