NOTE: This implementation does NOT call queue.drain if the queue is idle, which IMO makes sense. The docs state that queue.drain is a "Function that will be called when the last item from the queue has been processed by a worker." When the queue is idle and the user calls await queue.drained(), it's reasonable to assume that the user has already added and processed items from the queue, so queue.drain should have already been called when the last item was processed.
This PR fixes https://github.com/mcollina/fastq/issues/63 by returning early from
queueAsPromised.drained
when the queue is idle.NOTE: This implementation does NOT call
queue.drain
if the queue is idle, which IMO makes sense. The docs state thatqueue.drain
is a "Function that will be called when the last item from the queue has been processed by a worker." When the queue is idle and the user callsawait queue.drained()
, it's reasonable to assume that the user has already added and processed items from the queue, soqueue.drain
should have already been called when the last item was processed.