- Promises can be in one of three states: pending, resolved, or rejected.
- A promise is settled if it is either resolved or rejected.
- We construct a promise by using the
newkeyword and passing an executor function to the
setTimeout()is a Node function which delays the execution of a callback function using the event-loop.
- We use
.then()with a success handler callback containing the logic for what should happen if a promise resolves.
- We use
.catch()with a failure handler callback containing the logic for what should happen if a promise rejects.
- Promise composition enables us to write complex, asynchronous code that’s still readable. We do this by chaining multiple
- To use promise composition correctly, we have to remember to
returnpromises constructed within a
- We should chain multiple promises rather than nesting them.
- To take advantage of concurrency, we can use
Take this course for free