Promise.cast and Promise.resolve
Mark S. Miller
erights at google.com
Tue Jan 28 11:28:10 PST 2014
First, "q = Promise.fulfill(p)" never made any sense, as if p is pending,
then q cannot be fulfilled -- there's no non-promise value to fulfill it
to. Remember, a promise is fulfilled when it's (original) .then would
invoke its first (onFulfilled) callback. "fulfilled", "rejected", "pending"
are at the .then level of abstraction.
At the .flatMap level of abstraction, the fulfill-like concept is "accept".
Promise q accepts value (whether promise or non-promise) v when q's
(original) .flatMap would invoke its first (onAccept) callback. "accept" is
fully parametric, at the .flatMap level of abstraction, where "fully
parametric" is meaningful.
So, except for the name of the old operation we're no longer using, I agree
with Domenic. It is not that we renamed "Promise.fulfill" to
"Promise.resolve", we killed "Promise.fulfill" because it was incoherent,
and we renamed "Promise.accept" to "Promise.resolve".
For people concerned only about the .then level of abstraction, I see
little reason to ever use Promise.resolve rather than Promise.cast, and
much reason to prefer Promise.cast. But fwiw we did agree to express the
difference now, to be perceived by future and experimental uses of .flatMap
in the future.
On Tue, Jan 28, 2014 at 10:20 AM, Juan Ignacio Dopazo <jdopazo at yahoo-inc.com
> On Tuesday, January 28, 2014 10:13 AM, Kevin Smith <zenparsing at gmail.com>
> My take is that the difference between "cast" and "resolve" is so
> subtle that I don't think it captures developer intention. In
> other words, if I see some code calling Promise.cast(otherPromise),
> I can't be sure that the developer made an intentional choice over
> Note that `Promise.resolve(p)`, where p is a promise, does *not* return an
> eventual for the eventual value of p. Rather, it returns an eventual for
> p, literally. Promises should be considered fully parametric (in other
> words, nestable).
> That's not true as per the last consensus. There was `Promise.fulfill(p)`
> which would've nested promises, but it was left for ES7 to investigate
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss