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

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.

主站蜘蛛池模板: 唐河县| 永德县| 大石桥市| 黄龙县| 大埔县| 灵台县| 博野县| 梅河口市| 贵德县| 张家界市| 余庆县| 肥乡县| 江口县| 德清县| 丰城市| 无锡市| 琼海市| 阿鲁科尔沁旗| 麟游县| 固原市| 滁州市| 融水| 新邵县| 鹿泉市| 重庆市| 靖江市| 海原县| 横山县| 阳西县| 乌苏市| 永安市| 宜昌市| 广宗县| 论坛| 石城县| 阜新市| 崇仁县| 福鼎市| 乌兰察布市| 黔西县| 临清市|