I have a problem with jQuery 1.9.1 promises, where I potentially need conditional logic that will return another deferred and I'm not sure how to handle it. This was my best attempt, but as the comments indicate below, when I hit the else branch, I still hit the second .then() function, where I'm hoping I could go back to the user. Any patterns for how to handle such a scenario?
storage.provision(c)
.then(function(rc){
if(rc === 0){
storage.write(c);
}else{
return options.onSuccess(rc); //how i got back to the users callbacks/promise, but this
//takes me to the .then below
}
})
//storage.write returns a promise as well, do I do another .then
// like this?
.then(function(rc){
//I was hoping this would catch, the storage.write() case, and it does, but it also catches
//the retun options.onSuccess(rc) in the else case.
options.onSuccess(rc);
})
.fail(function(e){
//handle error using .reject()
});