Promises Consensus with /A+ terminology
Anne van Kesteren
annevk at annevk.nl
Thu Aug 1 09:07:36 PDT 2013
I basically took Tab's email and rewrote the terminology. I omitted
the issues for brevity. Hopefully this helps.
For the purposes of this email, a promise "fulfilling" or "rejecting"
means that its resolver's fulfill() or reject() method was called, or
the equivalent internal magic. "settle" means "fulfill or reject".
"resolve" means "adopt or fulfill, depending on whether the value is a
promise-like or not" (in other words, what the resolver's resolve()
method does). "adopt" means fulfilling or rejecting with the same
value as the adopted promise.
Promises have both a .then() and a .flatMap() method.
1. p.flatMap() does "single-level" resolution:
* whatever p settles to, gets passed to the flatMap() callbacks.
* The callback return value *must* be a promise-like, which is
adopted by the output promise; otherwise, the output promise rejects
with a TypeError.
2. p.then() does "recursive" resolution on the input side (per
consensus following 2 TC39-meetings ago):
* if p fulfills to a promise-like, the .then() callbacks get moved
down to that promise-like until it either fulfills with a
non-promise-like, or rejects.
* Rejection calls the rejection callback without delay; no extra
resolution mechanics happen here.
* The callback return value can be a promise-like or not. If it
is, the output promise adopts it; if not, the output promise fulfills
3. The helper functions (Promise.every(), etc.) use .then() semantics.
That is, Promise.every() will eventually fulfill to an array of
More information about the es-discuss