title: Infinite loop with asynchronous callback pattern in javascript
body: <p>Suppose I want to send an asynchronous AJAX request to the server, and when it responds send another request and repeat forever:</p>
  
  <pre><code>function sendXHR(url, callback) {
      // Send XMLHttpRequest to server and call callback when response is received
  }
  
  function infinite() {
      sendXHR('url/path', infinite);
  }
  
  infinite();
  </code></pre>
  
  <p>I assume here we would run out of stack space pretty quickly, so how can I do this (without blocking)?</p>
  
  <p>The pattern of passing callbacks around rather than using <code>return</code> is particularly popular with <code>node.js</code>. How do people create infinite loops? I don't believe most JS engines do any kind of tail call optimisation.</p>