ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Promise Fulfilled vs. Resolved
    DEV/Javascript 2021. 6. 8. 10:50

    According to the MDN Promise page,

    A Promise is in one of these states:
    * pending: initial state, neither fulfilled nor rejected.
    * fulfilled: meaning that the operation was completed successfully.
    * rejected: meaning that the operation failed.

    According to ECMAScript 2015 Language specification,

    When the Promise function is called with argument executor the following steps are taken:

    ...

    The executor argument must be a function object. It is called for initiating and reporting completion of the possibly deferred action represented by this Promise object. The executor is called with two arguments: resolve and reject. These are functions that may be used by the executor function to report eventual completion or failure of the deferred computation. Returning from the executor function does not mean that the deferred action has been completed but only that the request to eventually perform the deferred action has been accepted.

    The resolve function that is passed to an executor function accepts a single argument. The executor code may eventually call the resolve function to indicate that it wishes to resolve the associated Promise object. The argument passed to the resolve function represents the eventual value of the deferred action and can be either the actual fulfillment value or another Promise object which will provide the value if it is fulfilled.

    The reject function that is passed to an executor function accepts a single argument. The executor code may eventually call the reject function to indicate that the associated Promise is rejected and will never be fulfilled. The argument passed to the reject function is used as the rejection value of the promise. Typically it will be an Error object.

    The resolve and reject functions passed to an executor function by the Promise constructor have the capability to actually resolve and reject the associated promise. Subclasses may have different constructor behaviour that passes in customized values for resolve and reject.

    - 25.4.3.1 Promise (Executor)

    The promise can be either fulfilled or rejected. The Promise executor is called with two arguments: resolve and reject.

    I wonder why they name the resolve function as 'resolve', not as 'fulfill', whereas the name 'reject' has commonly used for the reject function and the promise's rejected state.

Designed by Tistory.