[mochikit] Re: Defered.setFinal

2009-02-10 Thread Amit Mendapara
It's not just error handler, it should always be called at the end once result is available and all callbacks/errback (including default errback) are fired. setFinalizer: function(cb) { this._finalizer = cb; } if (this.chain.length == 0 && this._finalizer) { this.finalized = true; th

[mochikit] Re: Defered.setFinal

2009-02-10 Thread Per Cederberg
You mean like this? setFinalizer: function(cb) { this._finalizer = cb; } ... if (this.chain.length == 0 && this._finalizer) { this.finalized = true; if (res instanceof Error) { this._finalizer(res); } } Would that be acceptable to

[mochikit] Re: Defered.setFinal

2009-02-10 Thread Amit Mendapara
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 Bob Ippolito wrote: > Finalizing a Defer

[mochikit] Re: Defered.setFinal

2009-02-10 Thread Bob Ippolito
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 Pyt

[mochikit] Re: Defered.setFinal

2009-02-10 Thread Per Cederberg
I think this is a good idea. I needed something similar too, so I ended up writing an ugly hack that worked most of the time... 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 callback

[mochikit] Defered.setFinal

2009-02-10 Thread Amit Mendapara
Hi Per, 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 mo