-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft B #2
Comments
Note that this doesn't attempt to make synchronous retrieval very ergonomic, on the theory espoused by @unscriptable over in promises-aplus/promises-spec#61 (comment) that people should think twice and just use Implementations should feel free to provide sugar, of course: Q.isPending = function (promise) {
var inspected = promise.inspect();
return !("fulfillmentValue" in inspected) && !("rejectionReason" in inspected);
};
Q.isFulfilled = function (promise) {
return "fulfillmentValue" in promise.inspect();
};
Q.isRejected = function (promise) {
return "rejectionReason" in promise.inspect();
}; |
This seems very similar to the In a way, yeah, they are separate issues, but they do seem quite closely related, especially since it seems possible to solve both with |
The problem with |
Also, the |
Good points about settable properties. I wonder if it would be a problem in practice, but it's definitely a concern. I imagine that it's possible for I'm not convinced |
@briancavalier You have started describing something that is not at all This is exactly the road that led me to |
For example, given function isNotWaitingOnAnyone(promise) {
return promise.mostResolved() === promise;
} This does not work with your revised definition, showing the difference. |
Ok, I see what you're saying. In this draft, is the object returned by That said, I still feel like I haven't seen any compelling concrete use cases for sync inspection, so I'm still wondering why we should spec anything at all. I'm certainly open to it if people have a real need for it that can't be solved in a reasonable/performant way using |
Yeah, that's the intent.
Did you see #3? |
I like! Does this interfere with debugging tools that may invoke |
Oh, interesting! If it does, another name would be fine. I didn't know Node did that. On the other hand, maybe it would be a nice feature?? |
Yes node.js/util.inspect:
It expects the result to be a string though. I do think that providing an implementation of Other than that I'm fairly happy with this proposal (since D was rejected). How about |
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:
Motivation
TODO
Requirements: the
inspect
methodA promise implementing this specification must have an
inspect
method, which returns an object.inspect
fulfillmentValue
.rejectionReason
.inspect
fulfillmentValue
, whose value is equal to the promise's fulfillment value.rejectionReason
.inspect
fulfillmentValue
.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 notif (promise.inspect().fulfillmentValue)
or evenif (promise.inspect().fulfillmentValue !== undefined)
, but insteadif ("fulfillmentValue" in promise.inspect())
.The text was updated successfully, but these errors were encountered: