I want to know is there a difference between following two?
aPromiseObj.then(fn1); aPromiseObj.then(fn2); aPromiseObj.catch(fn3);
You have asked about "chaining" vs. "branching".
f2 represent asynchronous operations that return promises, yes there is a significant difference. For option 1:
fn2is not called until after the promise returned by
fn1has been resolved.
.catch()applies to an error in either
fn2will not be called if
For option 2:
fn2does not wait for
fn2is called as soon as
fn1returns similar to
.catch()does not apply to either because it is not on the promise that is created by either of the
fn2will be called regardless of an error in either.