Skip to content

Commit 68c873d

Browse files
committed
document pool.useConcurrency method
1 parent d5c26c5 commit 68c873d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/promise-pool.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,25 @@ const pool = PromisePool
6767
The default concurrency is `10`.
6868

6969

70+
#### Adjust the Concurrency of a Running Pool
71+
- *Added in `2.3.0`*
72+
73+
You can adjust the concurrency while processing tasks. You may use the `pool.useConcurrency(<num>)` method to increase or decrease the previously configured concurrency of a promise pool instance.
74+
75+
```js
76+
const pool = PromisePool
77+
.for(users)
78+
.withConcurrency(10)
79+
.process(async (user, index, pool) => {
80+
if (condition) {
81+
pool.useConcurrency(200)
82+
}
83+
84+
await User.createIfNotExisting(user)
85+
})
86+
```
87+
88+
7089
### Start Processing
7190
The `process` method should be the last call in your method chain because it starts the promise pool processing. The `process` method accepts an async callback (function) defining the processing for each item:
7291

0 commit comments

Comments
 (0)