Call setTimeout again after a certain period of time

problem description

I wrote a method A, which recursively calls itself every few seconds, and another method B is a websocket push. The first websocket push method A starts to execute, just half of the websocket execution comes the second push, the first timer and the second timer start, how to let him only execute the first timer.

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

  clearTimeout(self.setVar);
  (function(arr) {
    var i = 0,
    len = arr.length;
    (function setColor() {
      self.setVar = setTimeout(function() {
        if (i < len-1) {
          if (i > 0) {
            arr[i - 1].borderWidth = 0;
          }
          arr[i].borderColor = "45,215,16";
          arr[i].borderWidth = 2;
          i = i + 1;
          setColor();
        } else if(i===len-1){
          arr[i].borderColor = "45,215,16";
          arr[i].borderWidth = 2;
          arr[i-1].borderWidth = 0;
          i = i+1;
          setColor();
        }else{
          arr[i-1].borderWidth = 0;
          i = 0;
          setColor();
        }
      }, 5000);
    })(i);
  })(nodeExample);

what result do you expect? What is the error message actually seen?

May.12,2021

then save the timer
before each timer is emptied
check whether the timer is still there
it means that there is a task waiting for execution
it means that the task has been executed
you can execute the task again
by the way, save the timer

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e54a16-452c2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e54a16-452c2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?