Monday 27 November 2017

How to send X amount of requests per Y seconds?

Greetings,Is there any elegant and simple way (or node_modules) for me to send X amount of requests per Y seconds?Currently what I have is:// stop application after 1sec setTimeout(function() { clearInterval(requestInterval); }, 1000); // loop every 200 milliseconds to send request function loop() { requestInterval = setInterval(function() { // send request loop(); }, 200); } loop(); The above code should send 5 request and then it would stop, but my problem is I couldn't get it to send EXACTLY X amount of times, when I set a lower value of setInterval time, it would send request more than the amount I wish to send.Sorry if my question is not clear. Thanks in advance.

Submitted November 27, 2017 at 02:59PM by xjellyfishx

No comments:

Post a Comment