title: setTimeout for XHR requests
body: <p>quoting <a href="https://developer.mozilla.org/En/window.setInterval" rel="noreferrer">MDC</a>:</p>
  <blockquote>
  <p>If there is a possibility that your logic could take longer to execute than the interval time, it is recommended that you recursively call a named function using window.setTimeout.  For example, if using setInterval to poll a remote server every 5 seconds, network latency, an unresponsive server, and a host of other issues could prevent the request from completing in its alloted time.  As such, you may find yourself with queued up XHR requests that won't necessarily return in order.</p>
  <p>For such cases, a recursive setTimeout pattern is preferred:</p>
  </blockquote>
  <pre><code>(function loop(){
     setTimeout(function(){
  
        // logic here
  
        // recurse
        loop();
  
    }, 1000);
  })();
  </code></pre>
  <blockquote>
  <p>In the above snippet, a named function loop is declared and is immediately executed.  loop is recursively called inside setTimeout after the logic has completed executing.  While this pattern does not guarantee execution on a fixed interval, it does guarantee that the previous interval has completed before recursing.</p>
  </blockquote>
  <p>I don't understand how this fixes the problem. Shouldn't I call loop() from inside the XHR callback and not from setTimeout?</p>