Closed glebec closed 7 years ago
So after all that, I realized this might not fall under the purview of the spec at all. In the spec, the resolution procedure for a downstream promise only runs when an upstream promise handler returns a value (which can, of course, only happen once). So… what might be the "spirit of the spec" in this case?
The first resolve call should always win.
please halp
@Nazimkhan123 — help with what?
Also: I am closing this issue as being related, but ultimately falling outside of, the spec. At most I would say that the spec could include a footnote suggesting that the answer by @ForbesLindesay.
pro
As I understand it, one effect of this rule is that the promise resolution procedure becomes "locked" to the first value/call, even if the passed-in value is itself a promise, and the promise resolution procedure is somehow triggered again with a normal value. To illustrate:
Example A: all promises (2.3.2.1)
However, 2.3.2.1 refers specifically to known promises (e.g. library constructs). I may be misreading something, but the spec doesn't seem to conclusively enforce that
promise
should wait on the eventual value of a thenable to the exclusion of subsequent resolutions. 2.3.3.3 and 2.3.3.3.3 come close:Were
resolvePromise
andrejectPromise
in this context intended to be singletons shared across all promise resolution procedure calls? The spec doesn't seem to enforce that. Whether this is an ambiguity or an inconsistency, libraries which pass the compliance tests may exhibit different behavior. Let's look at some examples:Example B1: Potential thenable, V8 promise
V8 Promises enforce waiting on thenables to the exclusion of later resolve calls, similar to 2.3.2.1. However…
Example B2: V8 thenable, Potential promise
Swap the roles around, and Potential has different behavior from V8 despite passing the A+ compliance tests. Is this a hole in the tests, or something that is intended to go either way depending on the whims of the library?
Others
Bluebird behaves like V8 in this respect. So do
Q
,ayepromise
,avow
,when
,rsvp
, andaplus-promesse
.Conclusion
To summarize: