Promises

A promise is an object which can be returned synchronously from an asynchronous function. It will be in one of 3 possible states:

  • Fulfilled: onFulfilled() will be called (e.g., resolve() was called)

  • Rejected: onRejected() will be called (e.g., reject() was called)

  • Pending: not yet fulfilled or rejected

A promise is settled if it’s not pending (it has been resolved or rejected). Sometimes people use resolved and settled to mean the same thing: not pending.

Once settled, a promise can not be resettled. Calling resolve() or reject() again will have no effect. The immutability of a settled promise is an important feature.

Promises following the spec must follow a specific set of rules:

  • A promise or “thenable” is an object that supplies a standard-compliant .then() method.

  • A pending promise may transition into a fulfilled or rejected state.

  • A fulfilled or rejected promise is settled, and must not transition into any other state.

  • Once a promise is settled, it must have a value (which may be undefined). That value must not change.

Promises

results matching ""

    No results matching ""