After each of my promises I perform a then, in this then I check if the user wishes to cancel the promise chain.
this.getData
.then(function(data){
self.shouldContinue(self.myNextMethod, data);
})
///more promises
Here is the check to see if the chain should continue:
p.shouldContinue = function(cb, args){
if(this.cancelCurrentRequest) {
if(typeof this.currentRequest.abort === 'function')this.currentRequest.abort();
return $.Deferred(function (d){ return d.reject();}).promise();
}
this.currentRequest = cb.apply(this,args);
return this.currentRequest;
};
The problem I am having is passing arguments to the method if it should continue.
For example, I am passing 'data' from getData then this needs to be passed to myNextMethod.
Currently it's undefined.