heapsource/node-orch-amqp — pull request #4 by jhansche (2013-10-03 18:05:50+00:00)
Title: Fix race condition in `onIssueQueue()`.

If `onIssueQueue()` is called with the same queueName multiple times,
the second call may have its callback invoked with an `AmqpQueue`
instance that has not yet assigned `AmqpQueue#_queue`. That results
in attempting to invoke `_queue.subscribe()` when `_queue` is still
`undefined`.

This fixes the race condition by assigning `_queue` immediately as
the return value from `connection.queue()` and at the same time
listening for the `bindQueueOk` event on that object, which will
invoke the `onIssueQueue` callback.

Then we still keep the `queue.bind()` call inside the `amqpQueueReady()`
callback function so it will only be bound when AMQP library says
it is ready to be used.