the result of an asynchronous process. • The Promise can either: – Resolve with the successful output of the process or – Reject with an error • A Promise is settled (resolved or rejected) exactly once. • Upon settlement, the Promise will call any registered callbacks.
Promise directly. • With Promise.resolve() we can create a Promise that resolves immediately. • Promise.reject() returns a Promise that rejects immediately.
Promises, allowing callbacks to be chained. • Each Promise in the chain resolves to the return value of the previous callback, allowing the construction of a pipeline.
Promise, it is inserted into the chain prior to the next handler. • This 'flattening' allows chains of asynchronous operations to occur without nesting.
• One application is to loop asynchronously over a series of HTTP requests. • In this way, we can control the end of the loop based on the contents of the requests.
bones, but provides a useful baseline for this functionality going forward. • A more full-featured promise library is bluebird, which is available for browsers and for Node.js. • jQuery includes something called a Promise, but as it does not support chaining of return values it is not as useful.