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

  • Start another timer. Put a sign of start and erase after a while. Direct methods of delay, though offered, do not work very much ... - DNS
  • @DNS is another setInterval? - Sonfire
  • Yes, one more. ( timeOut ) Before switching on, set delay=true On the functional, set the if(!delay)... check if(!delay)... after a lapse of time, reset the flag. - DNS
  • @DNS did not understand how "over time, reset the sign" - Sonfire
  • delay = true; setTimeout(function(){delay=false;},500) delay = true; setTimeout(function(){delay=false;},500) - DNS

0