p-queue
p-queue copied to clipboard
Next `interval` is ignored after `await queue.add(...)`
Version: 7.3.4
When queueing tasks, if one is awaited (e.g. because a subsequent task depends on its result), then the next task will begin – ignoring the queue's interval.
Reproduction
const queue = new PQueue({
intervalCap: 1,
interval: 1000,
});
queue.add(() => { console.log(new Date(), 'Finished task 1.') });
queue.add(() => { console.log(new Date(), 'Finished task 2.') });
queue.add(() => { console.log(new Date(), 'Finished task 3.') });
await queue.add(() => { console.log(new Date(), 'Finished task 4.') });
await queue.add(() => { console.log(new Date(), 'Finished task 5.') });
await queue.add(() => { console.log(new Date(), 'Finished task 6.') });
Logs:
2023-04-29T22:37:41.080Z Finished task 1.
2023-04-29T22:37:42.081Z Finished task 2.
2023-04-29T22:37:43.082Z Finished task 3.
2023-04-29T22:37:44.083Z Finished task 4.
2023-04-29T22:37:44.084Z Finished task 5.
2023-04-29T22:37:45.085Z Finished task 6.
I would expect these tasks to take no less than 5 seconds to complete, as they do when all or none of them use await. However, task 5 runs immediately after task 4.