Skip to content

Draft B #2

@domenic

Description

@domenic

Promises/A+ Extension: Synchronous Inspection

This proposal extends the Promises/A+ specification to cover synchronous inspection of a promise's fulfillment value or rejection reason.

It is not expected that all Promises/A+ implementations will include this extension. If the features of this extension are desired, you should test for them:

if (typeof promise.inspect === "function") {
  // Use the `inspect` method, assuming it conforms to the contract below.
}

Motivation

TODO

Requirements: the inspect method

A promise implementing this specification must have an inspect method, which returns an object.

  1. When the promise is pending, the object returned by inspect
    1. must not have a property named fulfillmentValue.
    2. must not have a property named rejectionReason.
  2. When the promise is fulfilled, the object returned by inspect
    1. must have a property named fulfillmentValue, whose value is equal to the promise's fulfillment value.
    2. must not have a property named rejectionReason.
  3. When the promise is rejected, the object returned by inspect
    1. must not have a property named fulfillmentValue.
    2. must have a property named rejectionReason, whose value is equal to the promise's rejection reason.

Note

Since fulfillment values and rejection reasons can be any valid JavaScript value, including undefined, this specification hinges on the difference between a property being present and it being absent. That is, the proper way to synchronously test for a promise being fulfilled is not if (promise.inspect().fulfillmentValue) or even if (promise.inspect().fulfillmentValue !== undefined), but instead if ("fulfillmentValue" in promise.inspect()).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions