Some notes to remind future me why Promises are pretty neat.
What do they give me?
- They let you regain error handling for asynchronous operations.
- They let you avoid nested callbacks (and the pyramid indentation that comes with them).
Can I use them?
Any important details?
- Promises can start executing the instant they have been instantiated. However, this does not strictly mean that they will be.
- If you call
.then(success_function, failure_function)on a Promise, the appropriate
functionwill not be called until a Promise has settled — either fulfilled or rejected.
.catch()is equivalent to calling
I need help visualising them
Try Promisees — it’ll visualise and animate the promise-y code you give it. You can also slow down the animation and record animated GIFs!