I've been using Mochikit's Deferred object for a while now and there
are some characteristics which I don't like about it. My most disliked
one being that exceptions thrown in the callback will cause the errback
to run:
var async = doNetworkRequestAndReturnDeferred();
async.addCallback(function() {
alert("Success!");
doSuccessStuff();
doOtherStuff();
});
async.addErrback(function() {
alert("Failure!");
revertChanges();
});
In the above code, if my callback is buggy and throws an exception (or
an external library that I'm using throws an exception), then errback
will be called and the user will see "Success!" and then "Failure!".
But the failure had nothing to do with the async request, which is what
errback is only for. In my opinion, when the async request logic has
finished, either the request was successful and callback should be
called, or it wasn't unsuccessful and errback should be called. It
should never call both callback and errback. In other words, callback
should *only* handle the case that the async request was successful and
errback should *only* handle the case that the async request failed.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---