title: Blocking queue in Javascript
body: <p>I need to create a blocking queue in Javascript. There are <code>pop()</code> and <code>shift()</code> methods in <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop" rel="nofollow">Array.prototype</a>, but the description says:</p>
  
  <blockquote>
    <p><strong>Return value:</strong> The last element from the array; <em><code>undefined</code> if the array is empty.</em></p>
  </blockquote>
  
  <p>I need a method which does <strong>not</strong> return <code>undefined</code>, but waits until there is some element to return.</p>
  
  <p>The purpose is, that my code is driven by multiple asynchronous operations which pushes elements to the queue and I need to process them.</p>