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

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.
<http://taskjs.org/#then>

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:

fu.progress(cb).then(cb,cb)

If you do it in the opposite order, like:

fu.then(cb,cb).progress(cb)

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.

~TJ

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