5

Is it possible to kill an asynchronous function call in node.js or do I have to call the function and then another one to kill the whole process after a specific amount of time?

5
  • You can use return within the function. Commented Feb 20, 2013 at 15:55
  • I know, but I'm talking about functions I didn't write. So I wanna start third party functions, and kill them if they run too long. Commented Feb 20, 2013 at 17:08
  • code code code? without code this cannot be answered Commented Feb 20, 2013 at 17:32
  • 1
    Not in any general way, no. You only could if the asynchronous call returned an object that provided a means of canceling the operation it's tied to. Commented Feb 20, 2013 at 17:35
  • 1
    Node is single-threaded. How are you going to check whether it has taken too long? Commented Feb 20, 2013 at 21:40

1 Answer 1

1

Probably not, But check following code, you can get some idea to achieve the stuff.

var logrunningFunction = function(){
  setTimeout(function(){
    console.log("Delayed");
    cb();
  }, 5000);

};


var cb = function(){
  console.log("long running function completed");
};
logrunningFunction(cb);

setTimeout(function(){
  cb = function(){
    console.log("Overwrite long running handler");
  };
},1000);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.