Before all examples, you will need:

This creates and returns a new promise. resolver must be a function. The resolver function is passed two arguments:

This function checks if the obj is a Promise , or could be cast ed.

A special function that takes a dictionary of promises and turns them into a promise for a dictionary of values. In other words, this turns an dictionary of promises for values into a promise for a dictionary of values.

This function wraps the obj act as a Promise if possible. Python Future s are supported, with a callback to promise.done when resolved. Have the same effects as Promise.resolve(obj) .

Returns a promise for a list. If it is called with a single argument then this returns a promise for a copy of that list with any promises replaced by their fulfilled values. e.g.

Converts values and foreign promises into Promises/A+ promises. If you pass it a value then it returns a Promise for that value. If you pass it something that is close to a promise (such as a jQuery attempt at a promise) it returns a Promise that takes on the state of value (rejected or fulfilled).

promise.then(did_fulfill, did_reject)

This method follows the Promises/A+ spec. It explains things very clearly so I recommend you read it.

Either did_fulfill or did_reject will be called and they will not be called more than once. They will be passed a single argument and will always be called asynchronously (in the next turn of the event loop).

If the promise is fulfilled then did_fulfill is called. If the promise is rejected then did_reject is called.

The call to .then also returns a promise. If the handler that is called returns a promise, the promise returned by .then takes on the state of that returned promise. If the handler that is called returns a value that is not a promise, the promise returned by .then will be fulfilled with that value. If the handler that is called throws an exception then the promise returned by .then is rejected with that exception.

promise.catch(did_reject) Sugar for promise.then(None, did_reject) , to mirror catch in synchronous code.