Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next interval is ignored after await queue.add(...) #182

Open
duskcodes opened this issue Apr 29, 2023 · 0 comments
Open

Next interval is ignored after await queue.add(...) #182

duskcodes opened this issue Apr 29, 2023 · 0 comments

Comments

@duskcodes
Copy link

duskcodes commented Apr 29, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant