Skip to content
Ang Lee edited this page Sep 6, 2013 · 4 revisions

Ang's notes on Promises

Learning JavaScript Promises, specifially the Q.js library.

Notes

.then()

  • This is the key!!
  • A promise must provide a .then() method to access its current or eventual fulfillment value or rejection reason:
promise.then(onFulfilled, onRejected)

.done()

  • .done() method is much like .then(), the only difference is about error handling.
  • .done() method should be used to terminate chains of promises that will not be passed elsewhere.

We can call promise.then/done as many times as we want and as late or early as we want and we will always get the same result. For example, it's fine to call it after the promise has already been resolved.(source)

.all()

Clone this wiki locally