Is there any way in Node.js to kill an async operation and preventing it from completing (calling callbacks, or resolving promise) ?
To be more specific, let's say I did an http.get()
call. It is an async operation that eventually will call the callback passed, or fire an error event. But it takes too long and the logic in my code could say "hey, I have been waiting for so long, I don't want to wait any longer!" and do something else instead. The problem is, the callback will eventually be called, and that might mess up stuff! So yeah, is there a way to stop that callback from being executed? My idea was:
var notWaitingAnyMore = false;
http.get({}, function(res) {
if(notWaitingAnyMore) { // do stuff! }
});
//do some other stuff
//now fed up with waiting:
notWaitingAnyMore = true;
But this doesn't seem like a nice solution to me...