Skip to content

Commit ab30669

Browse files
committed
document promise pool support for iterables
1 parent bdf0847 commit ab30669

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

packages/promise-pool.md

+28
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,34 @@ const pool = PromisePool
8686
```
8787

8888

89+
### Create a Promise Pool from an Async Iterable
90+
You may also create a promise pool from an async iterable. The package detects whether you’re passing an array or an iterable and handles both.
91+
92+
```js
93+
const iterable = {
94+
async * [Symbol.asyncIterator] () {
95+
const items = [10, 20, 30]
96+
97+
for (const item of items) {
98+
await new Promise(resolve => setTimeout(resolve(item), item))
99+
yield item
100+
}
101+
}
102+
}
103+
104+
const pool = await PromisePool
105+
.for(iterable)
106+
.withConcurrency(5)
107+
.process(item => {
108+
//
109+
})
110+
```
111+
112+
```info
113+
**Notice:** you can’t use [corresponding results](#correspond-source-items-and-their-results) in combination with iterables, because the pool doesn’t know the final number of items.
114+
```
115+
116+
89117
### Start Processing
90118
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:
91119

0 commit comments

Comments
 (0)