mcollina / fastq

Fast, in memory work queue
ISC License
932 stars 47 forks source link

fix: queueAsPromised.drained() resolves while queue is idle #64

Closed 0xOlias closed 1 year ago

0xOlias commented 1 year ago

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 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.