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

Abort signals don't remove tasks from the queue #219

Open
noahm opened this issue Jan 26, 2025 · 0 comments · May be fixed by #220
Open

Abort signals don't remove tasks from the queue #219

noahm opened this issue Jan 26, 2025 · 0 comments · May be fixed by #220

Comments

@noahm
Copy link

noahm commented Jan 26, 2025

The documentation for the signal option of the add() method is misleading:

AbortSignal for cancellation of the operation. When aborted, it will be removed from the queue and the queue.add() call will reject...

However, when a providing an abort signal, the associated items are not removed from the queue. This is problematic when combined with an intervalCap:

const queue = new PQueue({
  concurrency: 1,
  interval: 1000,
  intervalCap: 1,
});

const controller = new AbortController();

for (let i = 0; i < 10; i++) {
  queue.add(() => console.log('foo'), { signal: controller.signal });
}
queue.add(() => console.log('Hello World'));

controller.abort();

In such a scenario I would expect to get "Hello World" logged immediately (or perhaps after 1 second) but instead all 10 of the cancelled tasks remain in the queue and are ejected one by one, causing "Hello World" to print after 10 seconds.

@noahm noahm linked a pull request Jan 26, 2025 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant