https://github.com/mcollina/hwp
https://github.com/mcollina/hwp
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mcollina/hwp
- Owner: mcollina
- License: mit
- Created: 2021-08-11T07:17:04.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-21T19:35:00.000Z (about 3 years ago)
- Last Synced: 2025-03-28T01:50:04.177Z (11 months ago)
- Language: JavaScript
- Size: 197 KB
- Stars: 61
- Watchers: 3
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - hwp
README
# hwp
Consume Async Interators with a highwatermark, i.e. in batches.
This allow for multiple processing happening in parallel instead of one at a time.
The default highwatermark is `16`.
## Install
```js
npm i hwp
```
## Usage
```js
import { forEach, map, mapIterator, mapper } from 'hwp'
import { pipeline } from 'stream/promises'
const expected = ['a', 'b', 'c']
async function * something () {
const toSend = [...expected]
yield * toSend
}
await forEach(something(), async function (item, { signal }) {
return someAsyncFunction(item, { signal })
}, 16)
const res = mapIterator(something(), async function (item, { signal }) {
return someAsyncFunction(item, { signal })
}, 16)
for await (const item of res) {
console.log(item)
}
console.log(await map(something(), async function (item, { signal }) {
return someAsyncFunction(item, { signal })
}), 16)
await pipeline(
something(),
mapper((item, { signal }) => {
return someAsyncFunction(item, { signal })
}, 16),
async function (source) {
for await (const item of source) {
console.log(item)
}
}
)
```
## License
MIT