Deferred objects have two main pools of callbacks, namely doneCallbacks and failCallbacks. Both pools are “linear”: the callbacks are stored one after the other in the order they were given in.
This linear structure seems to go against the “tree-like” structure one has to consider when handling errors. At every step, there are two cases: fail and pass.
if(err) {
// stuff
if(err) {
// stuff
} else {
// stuff
}
else {
// stuff
if(err) {
// stuff
} else {
// stuff
}
}
It seems that because of the imposed linearity of Deferreds, they are not very suited for error handling. Am I overlooking something?
It’s a bit wordy but this is from the jQuery documentation for
$.when():Source: http://api.jquery.com/jquery.when/
So if a
deferredobject resolves to an error then themaster deferredfiresfailCallbacksand it’s up to you to decide what to do with the possibly un-resolveddeferreds.