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);