title: Wait for asynchronous task in NodeJS while consuming RabbitMQ Queue
body: <p>Using amqp-lib in node.js (7) I am having trouble waiting for asynchronous tasks while consuming from a RabbitMQ queue.</p>
  
  <p>For example,</p>
  
  <pre><code>    channel.consume(exchange_name, doWork, {
          noAck: false
      });
  
      function doWork(msg) {
          log.info(JSON.parse(msg.content.toString()));
          setTimeout(function () {
              log.info("   Done");
              channel.ack(msg);
          }, 2000);
      }
  </code></pre>
  
  <p>This should, AFAIK retrieve a message from the queue, process it, then acknowledge the process is complete &amp; successful.</p>
  
  <p>However, when I run it vs a queue with 1000 messages, it will grab all 1000 messages &amp; start the process.  Then 2 seconds later, acknowledge everything is done.  </p>
  
  <p>Is it possible to wait for the process to finish &amp; then get the next one?  (a worker should not consume 10's of thousands of messages while it is waiting on another process).</p>
  
  <p>Thanks in advance</p>