Killing asynchronous function calls in node.js

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

+5
source share
1 answer

Maybe not, but check out the following code, you may get some idea to achieve this.

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);
+1
source

All Articles