I am using native Promise
s for making ajax requests with superagent
like this.
function callAPI() {
return new Promise(function () {
request.get('/some.json')
.end(function (error, res) {
resolve(res);
});
});
}
var reqProm = callAPI();
What I am wondering is, can I use this promise to cancel/abort the request made? I would think there should be a method in Promise.prototype
like the following.
function callAPI() {
new Promise(function (resolve, reject) {
this.req = request.get('/some.json')
.end(function (error, res) {
resolve(res);
});
});
}
Promise.prototype.abort = function () {
this.req.abort();
}
However, I'm getting an error saying Promise.prototype is readonly. Is there any better way to do this?