title: Is looping events in JavaScript using document.dispatchEvent possible?
body: <p>I'd like to create an event loop mechanism in JavaScript/DOM using only dispatchEvent calls. </p>
  
  <p>For example:</p>
  
  <pre><code>document.addEventListener("LoopingEvent", loop, true);
  var loop = function() {
      doSomeWork();
      updateUI();
      document.dispatchEvent(loopEvent);
  };
  var loopEvent = document.createEvent('Events');
  loopEvent.initEvent("LoopingEvent", true, true);
  document.dispatchEvent(loopEvent);
  </code></pre>
  
  <p>When run, a call stack OutOfRange error is thrown. If I change the loop handler's dispatch call to use a window.setTimeout delay it loops without error.</p>
  
  <p>Just wondering if there is a way to use dispatchEvent looping infinitely without resorting to setInterval or setTimeout? The advantage in a dispatchEvent looping pattern is that the calls occur when the work is done rather than at set time intervals. </p>
  
  <p>Thanks in advance for any insights... </p>