Understanding async using setTimeout
<p>I have a UI where I need animations to run smoothly. Every so often, I need to do a semi-large data calculation that makes the animation skip until it is this calculation is completed.</p>

<p>I am trying to get around this by making the data calculation <strong>async</strong> with <code>setTimeout</code>. Something like <code>setTimeout(calcData(), 0);</code></p>

<p>The whole code is something like this (simplified):</p>

<pre><code>while (animating) {
    performAnimation();
    if (needCalc) {
       setTimeout(calcData(), 0);
    }
}
</code></pre>

<p>But I still get a skip in the animation. It runs smoothly when I do not need to do any data calculations. How can I do this effectively? Thanks!</p>