Need for a blocking sleep in javascript
<p>I know, I know, it's not a good design. Non-blocking setTimeout or setInterval are a way better approach, but to implement non-blocking, you need to refactor the whole code to have callback points in my scenario. Let me explain:</p>

<ol>
<li>I have a function that aims to fetch an object from a cache (storage)</li>
<li>If the object is available, I take it</li>
<li>When the object is not available, I request for it and wait until available by polling, with an expiration counter/time. At one point (not too far) it will be available and then I return to the caller</li>
</ol>

<p>I <strong>cannot implement a callback because the chain of calls (stack) is very deep</strong> and complex and it is simply impossible to refactor all of the code to use asynchronous callbacks/etc. In this specific case I really need a single threaded blocking loop. </p>

<p><strong>Now here comes the question:</strong></p>

<p>I dont simply want to use a simple for-loop with a counter. This would consume too many CPU cycles and would cause computer fans to fire up ( even if for a few seconds ). I am looking to find out what is the slowest javascript commands (or set of commands) that I can use as a blocking approach such as:</p>

<pre><code>while ( needToContinue ) {
    slowestCommandOrFunction();
    needToContinue = checkIfNeedToContinue();
}
</code></pre>
