by an asynchronous function, in place of the eventual value • 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 handlers.
handlers registered for when it is settled. • Resolution handlers are registered with the then() method. • Rejection handlers are registered with the catch() method.
Promise, the result of that Promise is passed to the next handler. • This 'flattening' allows chains of asynchronous operations to occur without nesting.
not always known in advance whether a value will be a regular value or a Promise. • The Promise.resolve() function returns a Promise that resolves to the eventual value of its argument, whether that is synchronous or asynchronous.
managing asynchronous operations in ES6. • Compared to callback-passing, a Promise-based approach is more predictable: – The handlers are always called asynchronously – They are always called either once or not at all, as required by the result of the asynchronous operation – The function performing the asynchronous operation can just return a value, rather than caring about callbacks. • Promises also enable pipelining, as above, which can be a very readable programming style
and asynchronous functions • They require an entirely different way of programming that is not always well-matched to the problem at hand • A Promise library must be present, though this is becoming less difficult with time.
friendlier syntax for working with asynchronous functions. • An async function allows its contents to await the result of an asynchronous operation, treating it as a normal value.
standard feature of the Javascript platform. • Its tools allow asynchronous data to be processed in a pipeline style, with each stage of the pipeline allowed to be asynchronous. • ES2017 will allow a more conventional programming style with the async and await keywords, but will still depend on Promises to make that happen.