IT:AD:Promise:HowTo:Chaining Handlers/Together
Summary
We've already seen that then() is how we associate a Success (and optionally a Failure) handler to a promise:
doSomethingThatReturnsAPromise().then(OnSuccess,OnFailure);
But a key concept of JQuery's promises architecture is that every then() method also returns a promise…so they can be chained together…
Process
Continuing from our previous example:
doSomethingThatReturnsAPromise()
.then(null, OnFailureA)
.then(OnSuccessB,OnFailureB)
.then(OnSuccessC);
which will run OnSuccessB and OnSuccessC if all goes well, and OnFailureA, OnFailureB if things go to pot.