lundi 2 mars 2015

how to break promise chain


I a promise in such fashion,



function getMode(){
var deferred = Promise.defer();

checkIf('A')
.then(function(bool){
if(bool){
deferred.resolve('A');
}else{
return checkIf('B');
}
}).then(function(bool){
if(bool){
deferred.resolve('B');
}else{
return checkIf('C');
}
}).then(function(bool){
if(bool){
deferred.resolve('C');
}else{
deferred.reject();
}
});

return deferred.promise;
}


checkIf returns a promise, and yes checkIf cannot be modified.


How do I break out of the chain at the first match? (any way other than explicitly throwing error?)





Aucun commentaire:

Enregistrer un commentaire