Calling a function every 60 seconds

后端 未结 13 2099
情书的邮戳
情书的邮戳 2020-11-22 08:24

Using setTimeout() it is possible to launch a function at a specified time:

setTimeout(function, 60000);

But what if I would l

13条回答
  •  情话喂你
    2020-11-22 09:19

    You can simply call setTimeout at the end of the function. This will add it again to the event queue. You can use any kind of logic to vary the delay values. For example,

    function multiStep() {
      // do some work here
      blah_blah_whatever();
      var newtime = 60000;
      if (!requestStop) {
        setTimeout(multiStep, newtime);
      }
    }
    

提交回复
热议问题