Skip to content

Commit 69d25d5

Browse files
committed
Improve backpressure docs
Fixes #87
1 parent f43fa4c commit 69d25d5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

readme.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,9 +798,9 @@ const queue = new PQueue({queueClass: QueueClass});
798798

799799
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).
800800

801-
#### How do I limit queue size to prevent memory issues?
801+
#### How do I implement backpressure?
802802

803-
Use `.onSizeLessThan()` to implement backpressure:
803+
Use `.onSizeLessThan()` to prevent the queue from growing unbounded and causing memory issues when producers are faster than consumers:
804804

805805
```js
806806
const queue = new PQueue();
@@ -812,6 +812,8 @@ queue.add(() => someTask());
812812

813813
Note: `.size` counts queued items, while `.pending` counts running items. The total is `queue.size + queue.pending`.
814814

815+
You can also use `.onRateLimit()` for backpressure during rate limiting. See the [`.onRateLimit()`](#onratelimit) docs.
816+
815817
#### How do I cancel or remove a queued task?
816818

817819
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.

0 commit comments

Comments
 (0)