W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2013

[futures] Folding .progress() into .then() for ProgressFuture

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Thu, 11 Apr 2013 16:32:49 -0700
Message-ID: <CAAWBYDBuQ05GnAKL0dSOHwECMxk-HG2tviU6-kD+9dSyLJ2p5Q@mail.gmail.com>
To: www-dom@w3.org
Task.js, one of the more popular independent promise libraries,
handles progress promises by just making .then() take three optional
callbacks, with the third being the progress callback.

I think we should adopt this.  You'll commonly want to register your
progress callbacks at the same time as your success/error callbacks,
so this is slightly more natural.

As well, right now it's easy to accidentally register your callbacks
in the wrong order when chaining and get the wrong results - the
correct way to register both is always:


If you do it in the opposite order, like:


you won't be listening to progress updates from fu, but rather from
the chained future returned by .then.  Given that the chained future
is always a plain Future afaict, and thus '.progress' will return
undefined, this is not what you want.  ^_^

As a further step, Task.js just makes all promises able to post
progress updates, rather than making it a special kind of promise you
have to request.  This sounds like it may be a good idea - by default,
futures just won't post any progress updates, so the third callback
won't do anything.  This is also friendlier to later "upgrading", if
we decide that a particular API originally specified as a plain Future
should post progress updates - right now it'll require a prototype
change, which has compat impact.

Received on Thursday, 11 April 2013 23:33:37 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:37:02 UTC