setInterval() browser queue
<p>I know that the <code>setInterval</code> function is pretty much single threaded. But if we set the time to a very small value like 50 milliseconds:</p>

<pre><code>setInterval(function()
{
  // do really heavy stuff
}, 50);
</code></pre>

<p>then the first generated event might not finish in time then I guess a second event is put into the browser's queue and then third, fourth etc. So basically this means that the browser's queue is getting bigger really fast and it's clearly not a good thing( is it? )</p>

<p>So far I've come with these two solutions:</p>

<p>1) Wait for the first event to finish and then call a second one(by using timeout):</p>

<pre><code>var func = function()
{
  setTimeout(function()
  {
    // do really heavy stuff and when it's finished call again
    func();
  }, 50)
}
</code></pre>

<p>2) Create a flag that monitors the event's state:</p>

<pre><code>var isIntervalInProcess = false;
setInterval(function()
{
  if ( isIntervalInProcess )
    return false;

  isIntervalInProcess = true;

  // do really heavy stuff

  isIntervalInProcess = false;

}, 50);
</code></pre>

<p>Are those best practices for getting rid of events overlaping?</p>
