javascript - How to add a while(1) loop in nodeJS -


in nodejs want function keep executing after every 5 seconds, , used while(1) loop time out of 5 seconds. not working.

    while(1){              var ms=4000;             ms += new date().gettime();             while (new date() < ms){}              execute(12345,0);      } 

in javascript can create tasks called on every interval needed using setinterval:

setinterval(functiontocalloninterval, intervalinmilliseconds);

setinterval(function() {    console.log('called every 5 seconds');  }, 5000);    setinterval(myfunc, 6000);    function myfunc() {    console.log('called every 6 seconds');  }

behold

setinterval timing not accurate can't count on vital situations.


Comments