-
Notifications
You must be signed in to change notification settings - Fork 1
Description
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.
- When the promise is pending, the object returned by
inspect
- must not have a property named
fulfillmentValue
. - must not have a property named
rejectionReason
.
- must not have a property named
- When the promise is fulfilled, the object returned by
inspect
- must have a property named
fulfillmentValue
, whose value is equal to the promise's fulfillment value. - must not have a property named
rejectionReason
.
- must have a property named
- When the promise is rejected, the object returned by
inspect
- must not have a property named
fulfillmentValue
. - must have a property named
rejectionReason
, whose value is equal to the promise's rejection reason.
- must not have a property named
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())
.