1

I have a node process running that do some unirest.get and unirest.post from time to time. I also have a type of web terminal from which I can see the overall progress of said unirest requests.

The problem is that I need to be able to cancel a specific request, but I can't find out how.

The structure is something like this:

var requests = [];
requests.push(unirest.post('someurl').end(somecallback));
requests.push(unirest.post('someurl').end(somecallback));
requests.push(unirest.post('someurl').end(somecallback));

And I want to do something like:

requests[1].cancel(); // but of course this method doesn't exist

since in this case I can't let the callback fires, since the goal is to cancel it to request the same url again, and without canceling it the callback would fire twice.

Anyone knows how to cancel/interrupt/destroy it?

4

1 回答 1

2

结果unirest.post('someurl').end(some callback)Request来自请求模块的对象。

所以,你可以使用abort 方法

requests[1].abort();
于 2016-02-20T08:23:03.363 回答