var promise1 = new Promise(function(resolve, reject) {
// ajax api call
});
var promise2 = new Promise(function(resolve, reject) {
// ajax api call
});
I want to be able to do something like -
if(a < b) {
promise1.cancel();
}
var promise1 = new Promise(function(resolve, reject) {
// ajax api call
});
var promise2 = new Promise(function(resolve, reject) {
// ajax api call
});
I want to be able to do something like -
if(a < b) {
promise1.cancel();
}
You can't cancel a Promise, but you can chain your promises with then
, and reject at any point.
new Promise((resolve, reject) => {
// step 1
})
.then((result) => {
if (!result) {
// Reject the promise chain
throw 'cancel';
} else {
return ... // step 2
}
})
.catch(err => {
// cancelled
});