Skip to content

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

Open
@noahm

Description

@noahm

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions