Book Image

Mastering JavaScript Promises

Book Image

Mastering JavaScript Promises

Overview of this book

Table of Contents (16 chapters)
Mastering JavaScript Promises
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Standard behaviors of the Promise API


There are few standards as per a promise/proposal, which has to be fulfilled for the true implementation of the concept. These standards are the keys to implement promises, and any library/language must comply with it for true implementation.

A promise does the following:

  • A promise returns an eventual value when a single completion of an operation occurs.

  • A promise has three states: unfulfilled (when a promise is waiting to be processed), fulfilled (when a promise has been completed and the desired result has been obtained), and finally, failed (when the result of a promise was obtained but not as anticipated).

  • Promise has a then property, which must be a function and must return a promise. In order to complete a promise, fulfilledHandler, errorHandler, and progressHandler must be called in.

  • With a promise, callback handlers return the fulfillment value from the returned promise.

  • The promise value must be persistent. This should maintain a state, and within...