-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Ang Lee edited this page Sep 6, 2013
·
4 revisions
Learning JavaScript Promises, specifially the Q.js library.
- General idea: http://youtu.be/ya4UHuXNygM?t=42m44s
- Basics: http://www.promisejs.org/intro/
- Promise/A+ spec (Promise/A+ is mostly Promise/A with some omissions, which is good for learning Promises!)
- Q documentation and Q API reference
.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)
- the
.then()
method must return a promise - internalize http://promises-aplus.github.io/promises-spec/#point-45
.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()
- Returns a promise that is fulfilled with an array containing the fulfillment value of each promise.
Use together with
.spread()
. - https://github.com/kriskowal/q/wiki/API-Reference#promiseall
- https://github.com/kriskowal/q/wiki/API-Reference#promisespreadonfulfilled-onrejected