sindresorhus / p-queue

Promise queue with concurrency control
MIT License
3.45k stars 185 forks source link

onIdle is not called #91

Closed gajus closed 4 years ago

gajus commented 4 years ago
setInterval(() => {
  console.log('>>>', [queue.size, queue.pending]);
}, 1000);

await queue.onIdle(async () => {
  console.log('IDLE');
});

With this code, I get:

>>> [ 1, 5 ]
>>> [ 0, 5 ]
>>> [ 0, 4 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 3 ]
>>> [ 0, 2 ]
>>> [ 0, 1 ]
>>> [ 0, 0 ]
>>> [ 0, 0 ]
>>> [ 0, 0 ]

I expect to see IDLE after first >>> [ 0, 0 ].

gajus commented 4 years ago

Never mind. I have misread the documentation. There is no callback. It should have been:

setInterval(() => {
  console.log('>>>', [queue.size, queue.pending]);
}, 1000);

await queue.onIdle();

console.log('IDLE');