mcollina / fastq

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

promise queue drained() method never returns if the queue is already completed #63

Closed abierbaum closed 1 year ago

abierbaum commented 1 year ago

I was expecting that I could call drained() at any point and it would wait until the fastq was empty.

From the implementation: https://github.com/mcollina/fastq/blob/9435e99a3be7b494c347650ab7a1ae34051a0866/queue.js#L268 it looks like this isn't true if the fastq is already empty when you call it.

I think other people may expect it to work the way I did, so I am filing a bug in case.

0xOlias commented 1 year ago

yea, it's an unusual behavior. i use this workaround when i want to wait for a queue to be empty:

if (!queue.idle()) {
  await queue.drained();
}
mcollina commented 1 year ago

That looks like an amazing fix. Would you like to send a PR with that change?