Killing `Promise.fulfill`

Mark S. Miller erights at google.com
Mon Aug 19 18:48:59 PDT 2013


I agree that an AP2 system, which is what we are discussing, should not
have a method named .fulfill for the reasons you state. A promise which, at
the AP2.flatMap level is "accepted" or "adopted" is, at the AP2.then level
"resolved". I suggest the method in question be called .resolve, that it
accept, not recursively unwrap/flatten/assimilate at all. The AP2.flatMap
programmer will understand .resolve as accepting. The AP2.then programmer
will understand .resolve as resolving.


On Mon, Aug 19, 2013 at 6:34 PM, Domenic Denicola <
domenic at domenicdenicola.com> wrote:

> Mark, I completely agree with you. However, I think this somewhat ignores
> the issue of this thread. The problem with AP2, even completely ignoring
> `flatMap`, comes when you consider the behavior of the `Promise.fulfill`
> method. Namely, what does this code do?
>
> ```js
> var foreverPending = new Promise(() => {});
> var p = Promise.fulfill(foreverPending);
> ```
>
> Because the recursive unwrapping has moved to the `then` side, we have that
>
> ```js
> p.then(() => console.log("this will never be called"));
> ```
>
> Such a promise `p` *cannot* be called fulfilled, if its fulfillment
> handler will never be called. From existing Promises/A+ definitions, it is
> resolved, but pending. Yet it was returned by `Promise.fulfill`, making
> that method a lie.
>
> One could answer by saying that you should ignore `Promise.fulfill` (and
> the resolver's `fulfill` callback), and this would be justifiable. Indeed,
> just like `flatMap`, I expect `fulfill` to be ignored by Promises/A+ and
> the broader community of promise users. But it prevents a severe
> pedagogical difficulty, because on the one hand, we are telling people that
> the fundamental states of a promise are fulfilled, rejected, and pending,
> whereas on the other hand we are saying that `Promise.fulfill` is a broken,
> mis-named method that should never be used even if you want to produce a
> fulfilled promise. (Or rather, especially not then!)
>
> As to your message, I guess it is unclear to me whether you envision
> `Promise.fulfill` as part of the eventual TC39 consensus. Even if you
> don't, as of now it's part of the DOM folks design, and I was hoping to
> stop a mistake there as well.
>
>


-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130819/0498393b/attachment.html>


More information about the es-discuss mailing list