I have just started again improving the MochiKit Extensions. While
creating tests for the Ajax module, I found one problem (not bug, but
specific to the feature I'm trying to implement). I registered a
callback which should be fired at the end of all registered callbacks.
I achieved by modifying Async.js with a new method `setFinal` (not
addFinal as there should be only one finalizer) which gets fired when
`chain.length == 0`. It's simple. I would we happy if you add one such
function in MochiKit.Async.Defered...
Regards
--
Amit
d.addBoth(function (res) {d.addBoth(finalFunc); return res; });
It adds new callback once the first deferred result drops in,
hopefully after all the other callbacks have been added...
But a more formally correct solution would probably be a good idea.
Cheers,
/Per
Your hack won't work with my case as it would mark the deferred as
`chained` so consecutive addCallback/addErrback won't work. Considering
Bob's suggestion, I modified my patch to ensure no further
callback/errbacks can be registered.
Regards
--
Amit
On Tue, Feb 10, 2009 at 6:48 PM, Bob Ippolito<b...@redivi.com> wrote:
>
> Finalizing a Deferred should ensure that no further callback/errbacks
> are registered and it should attach a default error handler (success
> should be no-op). The most common problem I've seen with Deferreds is
> that an error occurs but nobody attached an error handler that far
> down the stack. [...]
In order to handle this case, we have overwrote the 'callback' method
in our subclass of the Deferred class, to add a default Errback that
at least logs the error.
A similar solution could be probably used also in MochiKit, allowing
the user to optionally specify a specific error handler / finalizer.
This will allow any further check, as once the Deferred is triggered
it is already impossible to add further callback/errback.
I will check anyway the fix added to the repository to see how to
improve our current extension with the committed fix.
Giulio Cesare