The Paradox of Partial Parametricity

Tab Atkins Jr. jackalmage at gmail.com
Fri May 24 14:03:04 PDT 2013


On Fri, May 24, 2013 at 12:40 PM, Brendan Eich <brendan at mozilla.com> wrote:
> Tab Atkins Jr. wrote:
>> What's more, if you're using .then() for things, but you're passing in
>> a callback from elsewhere that assumes it can return nested promises,
>> everything's still kosher!  If you chain another .then() off of it,
>> you'll still get a plain value; if you chain a .chain()/.flatMap() off
>> of it, you'll get the "real" return value of the inner promise.  This
>> wins for everyone, in every situation I've been able to think of.
>
> I couldn't attend the third day of the TC39 meeting, but from Mark's slides,
> I take it the solution -- or let's say "coping strategy" -- with AP3 is to
> always wrap {value: payload} if you want to chain.
>
> Mark, is that right?

Yeah, that's right, but like I keep saying, that means that "thenable
promises" and "chainable promises" are no longer interoperable without
ugly helpers - a chainable promise might stack promises (doing
{value:{value:{value:foo}}}), and if you call .then() on it, you end
up receiving that ugly stacked object, rather than the "foo" that you
want.

In my proposal, it all works great - you can start with chainable
promises and then call .then() on it, you get the internal "foo"
immediately, because .then() waits for all its internal promises to
resolve.  It can do this because *it knows what the internal promises
are* - they aren't some anonymous object designed solely to *defeat*
the ability of a promise to recognize them as promises.


>> I'm sorry that I'm not a TC39 member, and that the talks were prepared
>> before the conversations earlier this week that led me to discover
>> this particular combination that works best.  I think I could've
>> influence the conversation better had I been there. :/
>
> Not to worry, no final ultimate double-checked decision was reached. ;-)

Yeah, I know, but I've learned over time that influencing the
conversation early is useful.  ^_^

~TJ


More information about the es-discuss mailing list