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…

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.

  • /home/skysigal/public_html/data/pages/it/ad/promise/howto/chaining_handlers_together.txt
  • Last modified: 2023/11/04 01:54
  • by 127.0.0.1