Closed domenic closed 11 years ago
The fatal flaw with this idea, which is based off of https://github.com/promises-aplus/promises-spec/issues/61#issuecomment-11901800, is that fulfillmentValue
and rejectionReason
are just ordinary properties. In particular, promise consumers can set them and confuse other consumers.
This precludes the implementation of ever freezing the promise.
Yup, thus draft B.
This is inferior to Draft B; closing to prevent confusion from those thinking this is actively being considered for standardization under the Promises/A+ banner, but of course discussion is still welcome.
I was about to commit this for discussion, before I realized a potentially fatal flaw that made me contemplate Draft B (#2).
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+ implementors will implement this extension. If the features of this extension are desired, you should test for them as in the "Branding" section below.
Motivation
TODO
Requirements
Branding
An implementation of the synchronous inspection extension must signal that synchronous inspection is available by adding a truthy
synchronousInspection
property to everythen
method:Synchronous Inspection Properties
fulfillmentValue
.rejectionReason
.fulfillmentValue
, whose value is equal to the promise's fulfillment value.rejectionReason
.fulfillmentValue
.rejectionReason
, whose value is equal to the promise's rejection reason.fulfillmentValue
orrejectionReason
, this must not have any impact on the promise's state.Suggestions
If feasible, an implementation is encouraged to make
fulfillmentValue
andrejectionReason
properties non-writable, to discourage attempts to set them.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 notif (promise.fulfillmentValue)
or evenif (promise.fulfillmentValue !== undefined)
, but insteadif ("fulfillmentValue" in promise)
.