Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Killing async function calls in node.js

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?

like image 460
K.. Avatar asked Nov 13 '22 11:11

K..


1 Answers

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);
like image 126
HILARUDEEN S ALLAUDEEN Avatar answered Nov 15 '22 00:11

HILARUDEEN S ALLAUDEEN