Node.js crashes when using long interval in setinterval

前端 未结 2 2029
闹比i
闹比i 2020-12-15 16:29
function createSasTokenTimer() {    
    console.log(\"Hello\");
}

setInterval(createSasTokenTimer, 3000000);

I run this code and after 50 minutes

2条回答
  •  情深已故
    2020-12-15 16:51

    Instead of calling the Function Directly give it inside a callback.

    function createSasTokenTimer() {    
      console.log("Hello");
    }
    
    setInterval(function(){
     createSasTokenTimer();
    }, 3000000);
    

    Using this method, you are passing an anonymous function to setInterval. It will call this function once per interval, which is 3000000 miliseconds in this example.

    For now, you can probably just use this code. For further understanding, I suggest researching anonymous functions and closures.

    Hope this helps.

提交回复
热议问题