title: Blocking "wait" function in javascript?
body: <p>As part of a Javascript project I'm working on, there are some synchronous ajax calls <em>(I guess that makes it "sjax", but I digress)</em>. I'm now writing a debugging panel which would allow me to test out the site with some artificially simulated network conditions by wrapping <code>$.ajax</code>. Simple things: faking a 500 response etc, and making the ajax calls take much longer.</p>
  
  <p>For the asynchronous calls, it's simple. When the real response comes back, add a <code>setTimeout</code> to make it wait for the artificial response time before triggering the callback. However, this doesn't work with the synchronous calls obviously, since <code>setTimeout</code> isn't synchronous.</p>
  
  <p>So, is there a way to make a Javascript program perform a blocking wait for a set amount of time?</p>
  
  <p>The only thing I could think of would be something like this:</p>
  
  <pre><code>function wait(ms) {
      var start = +(new Date());
      while (new Date() - start &lt; ms);
  }
  </code></pre>
  
  <p>Is there a better solution?</p>
  
  <p><em>(Also, please assume there's a good reason for the blocking ajax calls... <code>:-\</code>)</em></p>