The then method registers success and error callbacks for a Promise and returns another Promise. It applies transformations to a value that will exist later, allowing dependent asynchronous work to read like a sequence instead of nested callbacks. section 8.2
Waiting for an asynchronous result
var promiseDemo = new Promise(function(resolve, reject) { Scheduler.delay5(function () { resolve('Done!'); }); }); promiseDemo.then(function(status) { console.log('After 5 seconds, the status is: ' + status); }); Each then callback receives the fulfilled value. A second optional callback can handle rejection, or error handling can be deferred to one catch at the end. section 8.2
Chaining with then supports several useful patterns:
- Transform data through successive asynchronous steps without creating nested callback levels. section 8.2
- Promisify callback-based APIs such as getJSON, then handle failures locally or with a final catch. section 8.2
- Combine sequential then stages with Promise.all when several requests can run concurrently. section 8.2
Figure 8.6. A sequence of chained promises joined via the then method. Each then clause is executed serially with one promise value after the next as soon as each is fulfilled.
A sequence diagram makes the value flow through serial then clauses easy to follow. section 8.2




