Chaining Promises
.then
callbacks can be synchronous or return another Promise- If the
.then
callback returns a Promise, the next.then
will wait until the returned promise finishes - This collapsing helps make asynchronous code much easier to follow
- You don't need nested callbacks. Can orchestrate everything in one place
delay(1000)
.then(() => console.log("Hi"))
.then(() => delay(1000))
.then(() => console.log("I'm"))
.then(() => delay(1000))
.then(() => console.log("Ryan"))
4 / 23