title: Managing a Queue with Multiple, Asynchronous Calls
body: <p>I'm writing a queue in JavaScript that will be processed by several "servers" asynchronously. I'm concerned that two servers might retrieve the same item from the queue. It doesn't appear to be happening now, but I don't want to leave it to chance. From my knowledge, JavaScript is single-threaded; does that permit the assumption that even though there will be several requests at the same time, JavaScript uses it's own queue to execute the function?</p>
  
  <pre><code>function getJob() {
    if(jobs.length &gt; 0) {
        var job = jobs.shift();
        $('#jobStatsQueueCount').text(jobs.length);
        return job;
    } else {
        return null;
    }
  }
  </code></pre>
  
  <p>Here is the full code:</p>
  
  <p><a href="http://jsfiddle.net/L7yaB/5/" rel="nofollow">http://jsfiddle.net/L7yaB/5/</a></p>