Skip to content

Commit 6b8ff60

Browse files
committed
Add FAQ about removing tasks
Closes #227 Closes #76
1 parent 7fea658 commit 6b8ff60

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

readme.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,23 @@ const queue = new PQueue({queueClass: QueueClass});
562562

563563
They are just different constraints. The `concurrency` option limits how many things run at the same time. The `intervalCap` option limits how many things run in total during the interval (over time).
564564

565+
#### How do I cancel or remove a queued task?
566+
567+
Use `AbortSignal` for targeted cancellation. Aborting removes a waiting task and rejects the `.add()` promise. For bulk operations, use `queue.clear()` or share one `AbortController` across tasks.
568+
569+
```js
570+
import PQueue from 'p-queue';
571+
572+
const queue = new PQueue();
573+
const controller = new AbortController();
574+
575+
const promise = queue.add(({signal}) => doWork({signal}), {signal: controller.signal});
576+
577+
controller.abort(); // Cancels if still queued; running tasks must handle `signal` themselves
578+
```
579+
580+
Direct removal methods are not provided as they would leak internals and risk dangling promises.
581+
565582
## Maintainers
566583

567584
- [Sindre Sorhus](https://github.com/sindresorhus)

0 commit comments

Comments
 (0)