title: Two queues, one with concurrency 1 another with concurrency 3
body: <p>I have this situation with:</p>
  
  <pre><code>const q1 = async.queue((task,cb) =&gt; task(cb), 1);
  const q2 = async.queue((task,cb) =&gt; task(cb), 3);
  </code></pre>
  
  <p>basically, the situation is - if I can get a lock on q1, I can process up to 3 things concurrently in q2. Aka, most things in my program have to run serially, but certainly things can run in parallel, but only if they acquire a "lock" on q1 first. However, writing this turns out to be much harder than expected. I think it's akin to the reader/write locking problem.  <a href="https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock</a></p>
  
  <p>In other words, I can only process things in q2 if I have a lock on q1. One problem with implementing this, is if I always have to acquire a lock on q1 in the critical section of q2, then I won't be able to use a higher concurrency level in q2, it will always be serial.</p>
  
  <p>The only idea I have right now is to flip a boolean, something like this:</p>
  
  <pre><code>let q2HasLock = false;
  
  if(q2hasLock === true){
    q2.push(cb =&gt; ...);
  }
  else{
    q1.push(cb =&gt; ...);
  }
  </code></pre>
  
  <p>then I can use this:</p>
  
  <pre><code>q2.drain = () =&gt; {
     q2HasLock = false;
  };
  </code></pre>
  
  <p>but the remaining part is I don't know how/when to flip <code>q2HasLock</code> to <code>true</code>. Hopefully you understand the problem/idea. Another problem with this implementation, is that requests to push to q2 could starve requests that are going to q1, so I could do this:</p>
  
  <pre><code>let q2HasLock = false, count = 0 ;
  
  if(q2hasLock === true &amp;&amp; count &lt; 3){
    count++;
    q2.push(cb =&gt; ...);
  }
  else{
    q1.push(cb =&gt; ...);
  }
  
  q2.drain = () =&gt; {
     count = 0;
     q2HasLock = false;
  };
  </code></pre>
  
  <p>This is getting hairy - I would like to implement this as simply as possible!</p>