hwp

0.3.0 • Public • Published

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

npm i hwp

Usage

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.3.0
    157
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.3.0
    157
  • 0.2.0
    1
  • 0.1.1
    1
  • 0.1.0
    1

Package Sidebar

Install

npm i hwp

Weekly Downloads

160

Version

0.3.0

License

MIT

Unpacked Size

15.5 kB

Total Files

8

Last publish

Collaborators

  • matteo.collina