No way to cancel a request #44

hugovincent opened this Issue Oct 23, 2011 · 2 comments

2 participants


Sometimes you need to cancel a request and guarantees that the request callback does not get executed.

Here is an implementation (note that in Node 0.5 builds, but not 0.4.x, removeAllListeners with no arguments can be used instead of manually manipulating _events), however it is apparently incorrect as I find the callback still gets executed and I need to manually check the .cancelled key in my callback:

restler.Request.prototype.cancel = function() {
    if (this.options.originalRequest) {
      this.options.originalRequest._events = {};
    this._events = {};
    this.cancelled = true;

Does RESTler do some kind of internal queueing or something that is preventing this from working?


Should probably use request.Abort() for this.


Thanks @ayoung, the problem is requests that were in flight at the time they were .cancel()led [either as above, or using .abort()] don't seem to actually cancel, which is to say, the callback still gets called if data is returned. I can only repeat this on one (particularly slow, rate limited) server, so it's possible something weird is happening (with the rate limiting?), but the ability to cleanly abort a request would be useful in other situations too.

@ayoung ayoung closed this in 3f21531 Jan 12, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment