Killing async function calls in node.js

Problem

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?

Problem courtesy of: K..

Solution

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);
Solution courtesy of: HILARUDEEN ALLAUDEEN

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.