p-queue icon indicating copy to clipboard operation
p-queue copied to clipboard

Other events

Open acrodrig opened this issue 5 years ago • 4 comments

It would be very nice to have the queue emit other events, such as empty.

acrodrig avatar Apr 08 '20 05:04 acrodrig

What other events than empty?

sindresorhus avatar Apr 08 '20 14:04 sindresorhus

Sorry, I should have been more explicit. I like the active event. I wish I had other events such as idle and empty. For example, I would like to do something like:

queue.on('empty', () => {
    // Since the queue is empty, we have time for other things
    console.log(`Will flush out metrics/logs now!`);
    logger.flush();
    metrics.flush();
});

Does this make sense? I could do some promise "calisthenics" on top of the queue.onEmpty, but I would need to keep "awaiting" repeatedly to get a callback every time the queue becomes empty.

Cheers and thanks for a great library.

acrodrig avatar Apr 08 '20 16:04 acrodrig

@acrodrig @sindresorhus I added idle event and submitted a PR with it #109

Ilaiwi avatar Apr 17 '20 10:04 Ilaiwi

I'd like to toss in a request for limitReached or some such that would notify when the queue is effectively paused because the intervalCap had been reached for a given interval. There's a good bit of processing that I'd like to do in that scenario.

shellscape avatar Apr 25 '20 01:04 shellscape