W3C home > Mailing lists > Public > public-script-coord@w3.org > April to June 2013

Re: Deprecating Future's .then()

From: Sam Tobin-Hochstadt <samth@ccs.neu.edu>
Date: Tue, 4 Jun 2013 09:55:15 -0400
Message-ID: <CAK=HD+ZdAtMkJn_k_f74WdfZm8fE_UWWuxVsL5n_62YN6zNo_w@mail.gmail.com>
To: Anne van Kesteren <annevk@annevk.nl>
Cc: "Tab Atkins Jr." <jackalmage@gmail.com>, "Mark S. Miller" <erights@google.com>, Sean Hogan <shogun70@westnet.com.au>, "www-dom@w3.org" <www-dom@w3.org>, "public-script-coord@w3.org" <public-script-coord@w3.org>, Alex Russell <slightlyoff@google.com>
On Tue, Jun 4, 2013 at 9:48 AM, Anne van Kesteren <annevk@annevk.nl> wrote:
> On Tue, Jun 4, 2013 at 8:55 AM, Sam Tobin-Hochstadt <samth@ccs.neu.edu> wrote:
>> Thinking about this more, I'm now unsure why both `fulfill` and
>> `resolve` are needed given the semantics of `.chain()` and `.then()`
>> described below.
>>
>> In particular, if `.then()` chains recursively *before* calling the
>> callback, then there's no difference between:
>>
>>     Future.resolve(x).then(v => ...)
>>
>> and
>>
>>     Future.fulfill(x).then(v => ...)
>>
>> even when `x` is a promise.  The only way to observe this is with `.chain()`.
>>
>> Thoughts?
>
> I'm just going to try to repeat what you said here to make sure I understand.
>
> Promise.resolve(val) creates a promise of val, regardless of whether
> val is a promise, has a callable then property, or anything like that.
> (In that sense it is equivalent to Future.accept() today.)
>
> promise.then() keeps unwrapping promise's internal value until it no
> longer has a callable then property at which point it invokes the
> relevant callback passed to promise.then(). (Exact algorithm TBD after
> broader agreement.)
>
> promise.chain() invokes its relevant callback with promise's internal value.
>
> promise.then() and promise.chain() return value (newPromise) is
> resolved with the return value of their callbacks after it has been
> unwrapped once.

That's exactly right.

Sam
Received on Tuesday, 4 June 2013 13:56:08 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:37:49 UTC