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

Re: Futures

From: Alex Russell <slightlyoff@google.com>
Date: Fri, 26 Apr 2013 20:24:57 +0100
Message-ID: <CANr5HFUGrnWBto8ACpQBDJJdSTfGAd6pamLZbxV97o=0iGg17Q@mail.gmail.com>
To: Tab Atkins <jackalmage@gmail.com>
Cc: Kevin Smith <zenparsing@gmail.com>, Brendan Eich <brendan@mozilla.com>, EcmaScript <es-discuss@mozilla.org>, Norbert Lindenberg <w3@norbertlindenberg.com>, "Mark S. Miller" <erights@google.com>, Markus Lanthaler <markus.lanthaler@gmx.net>, "public-script-coord@w3.org" <public-script-coord@w3.org>, Douglas Crockford <douglas@crockford.com>
On Apr 26, 2013 8:33 PM, "Tab Atkins Jr." <jackalmage@gmail.com> wrote:
>
> On Fri, Apr 26, 2013 at 11:25 AM, Kevin Smith <zenparsing@gmail.com>
wrote:
> > Actually, I may have gotten it terribly wrong (apologies).  In my
prototype
> > implementation, the following:
> >
> >     Future.accept(Future.resolve(1)).then(value => {
> >
> >         console.log(value !== 1);
> >         return Future.accept(Future.resolve(1));
> >
> >     }).then(value => {
> >
> >         console.log(value === 1);
> >     });
> >
> > logs
> >
> > - true
> > - true
> >
> > Is that what it should be doing, according to the DOM spec?  Anne, Alex?
>
> No, it should be "true", then "false".
>
> Future.resolve(1) returns a Future<1>.
>
> Future.accept(Future.resolve(1)) returns Future<Future<1>>.

This would all be easier to discuss if you weren't writing using invented
methods.

> If you call .then() on a Future<Future<1>>, the callback receives a
> Future<1> as its argument.
>
> If you return a Future<Future<1>> from the callback, the chained
> future adopts its state, which means that the chained future is now
> also a Future<Future<1>>.
>
> So, calling .then() on the chained future will give you the same
> result - the callback receives a Future<1> as its argument.
>
> (Using a mixture of Future.accept and Future.resolve in the way that
> you have makes things more confusing than necessary.  When called on a
> plain value, the two functions are identical.  They only act
> differently when you call them on a future.)
>
> ~TJ
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
Received on Friday, 26 April 2013 19:25:24 UTC

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