官术网_书友最值得收藏!

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 that state, the value must be preserved.

This API does not define how promises are created. It only provides a necessary interface that promise provides to promise consumers to interact with it. Implementations are free to define how promises are generated. Some promise may provide their own function to fulfill the promise and other promises may be fulfilled by mechanisms that are not visible to the promise consumer. Promises themselves may include other additional convenient methods as well.

主站蜘蛛池模板: 遵义市| 广州市| 贵州省| 常熟市| 江山市| 会东县| 固阳县| 荔浦县| 顺义区| 鱼台县| 菏泽市| 怀集县| 临颍县| 铜鼓县| 横峰县| 九江县| 宣恩县| 兴安盟| 故城县| 武功县| 嘉禾县| 华容县| 土默特右旗| 临安市| 疏勒县| 普安县| 抚松县| 广安市| 天津市| 大英县| 安泽县| 云霄县| 个旧市| 陆丰市| 平果县| 江阴市| 天水市| 宜兰县| 夏河县| 崇阳县| 甘孜县|