jQuery 1.9.1 のプロミスに問題があり、別の遅延を返す条件付きロジックが必要になる可能性があり、それを処理する方法がわかりません。これは私の最善の試みでしたが、以下のコメントが示すように、else ブランチをヒットしたときに、まだ 2 番目の .then() 関数をヒットしており、そこでユーザーに戻れることを望んでいます。そのようなシナリオを処理する方法のパターンはありますか?
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()
});