Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ export default class PQueue<QueueType extends Queue<RunFunction, EnqueueOptionsT
return new Promise((resolve, reject) => {
this.#queue.enqueue(async () => {
this.#pending++;
this.#intervalCount++;

try {
options.signal?.throwIfAborted();
this.#intervalCount++;

let operation = function_({signal: options.signal});

Expand Down
20 changes: 20 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,26 @@ test('should pass AbortSignal instance to job', async t => {
}, {signal: controller.signal});
});

test('aborted jobs do not use interval cap', async t => {
const queue = new PQueue({
concurrency: 1,
interval: 100,
intervalCap: 1,
});

const controller = new AbortController();

for (let index = 0; index < 5; index++) {
queue.add(() => {}, {signal: controller.signal}).catch(() => {}); // eslint-disable-line @typescript-eslint/no-empty-function
}

queue.add(() => {}); // eslint-disable-line @typescript-eslint/no-empty-function

controller.abort();
await delay(150);
t.is(queue.size, 0);
});

test('aborting multiple jobs at the same time', async t => {
const queue = new PQueue({concurrency: 1});

Expand Down