You need to make a delay in the setInterval request
var iid = null; iid = setInterval(doSomething, 1000); function doSomething() { var req; // ΠΎΡΠΏΡΠ°Π²ΠΈΡΡ if (req) { // ΠΡΠΎΠ²Π΅ΡΠΊΠ° Π½Π° ΠΎΡΠΈΠ±ΠΊΡ console.log(req); idx++; } else { // ΠΡΠΈΠ±ΠΊΠ° // ΠΡΠΆΠ½ΠΎ ΡΠ΄Π΅Π»Π°ΡΡ Π·Π°Π΄Π΅ΡΠΆΠΊΡ Π² 500ΠΌΡ console.log("Error"); } if (idx == 20) { // ΠΊΠΎΠ½Π΅Ρ ΡΠΈΠΊΠ»Π° clearInterval(iid); } } I tried setTimeout(function() {}, 500);
timeOut) Before switching on, setdelay=trueOn the functional, set theif(!delay)...checkif(!delay)...after a lapse of time, reset the flag. - DNSdelay = true; setTimeout(function(){delay=false;},500)delay = true; setTimeout(function(){delay=false;},500)- DNS