You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -798,9 +798,9 @@ const queue = new PQueue({queueClass: QueueClass});
798
798
799
799
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).
800
800
801
-
#### How do I limit queue size to prevent memory issues?
801
+
#### How do I implement backpressure?
802
802
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:
804
804
805
805
```js
806
806
constqueue=newPQueue();
@@ -812,6 +812,8 @@ queue.add(() => someTask());
812
812
813
813
Note: `.size` counts queued items, while `.pending` counts running items. The total is `queue.size + queue.pending`.
814
814
815
+
You can also use `.onRateLimit()` for backpressure during rate limiting. See the [`.onRateLimit()`](#onratelimit) docs.
816
+
815
817
#### How do I cancel or remove a queued task?
816
818
817
819
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