Chaining Promises

You can chain multiple promises to be executed serially by calling .then repeatedly

Chaining Promises
  • we have a sequence of asynchronous tasks to be performed one after another — for instance, loading scripts. How can we code it well? Promises provide a couple of recipes to do that.
  • Chaining works because because every call to a .then returns a new promise, so that we can call the next .then on it. When a handler returns a value, it becomes the result of that promise, so the next .then is called with it.
  • A handler, used in .then(handler) may create and return a promise. In that case further handlers wait until it settles, and then get its result.
  • Show example of promise with Fetch
Scroll to Top