I do XMLHttpRequest every second to the server, the server will respond with new messages. To call XMLHttpRequest every second, I use the setInterval() function inside SharedWorker .
However, since I make a request every second, I would like to know if setInterval() asynchronous or not?
For example, if one XMLHttpRequest request took 3 seconds to complete βdue to a delayβ, will I have three requests at the same time or will setInterval() wait until the first request completes before it takes 1 second and send another request?
Here is my code
function checkQueue(url) { var xhr = new XMLHttpRequest(); xhr.addEventListener("load", reqListener); xhr.open('GET', url, true); xhr.send(); } function reqListener () { var queue = JSON.parse(this.responseText); notifyAllPorts(queue); console.log(this.responseText); } setInterval( function() { checkQueue('/add-ons/icws/push.php') } , 1000);
source share