Reputation: 647
What would be the best way to realize the functionality of Ruby Timeout module in JavaScript?
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/timeout/rdoc/Timeout.html
e.g. to cancel (async) requests which take longer to finish than a given time?
EDIT:
To make clear what I want to achieve:
For example if I do a HTTP request in node.js e.g.
http.request(options, callback).end();
And I want to cancel the request if it takes longer than a given timeout. So unbind the callback or everything what is need to make sure the request has no further effect.
Upvotes: 2
Views: 188
Reputation: 9904
If you want to cancel an (to) long running process create a variable that is accessible within the closure (function) you create with setTimeout
someLongRunningHttpRequest = new HttpRequest("point://some/where")
#cancel the request after 5 seconds
setTimeout ->
someLongRunningHttpRequest.cancel()
, 5000
obviously you need an object that is "cancable" or you could simple ignore the result?
Upvotes: 1