Skip to content
This repository

No way to cancel a request #44

Closed
hugovincent opened this Issue · 2 comments

2 participants

Hugo Vincent Andrew Young
Hugo Vincent

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;
    return;
  };

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

Andrew Young
Collaborator

Should probably use request.Abort() for this.

Hugo Vincent

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.