parallel-transform-web
Parallel transform for web streams. Zero dependencies.
Note: does not preserve ordering.
Install
npm i parallel-transform-web
Usage
import { Parallel } from 'parallel-transform-web'
// a stream that yields random numbers, forever!
const randomNumbers = new ReadableStream({ pull: controller => controller.enqueue(Math.random() * 10) })
// run up to 10 transforms concurrently
const concurrency = 10
// identity transform that adds a short delay
const transformer = n => new Promise(resolve => setTimeout(() => resolve(n), n))
// parallelized transform stream
const delayer = new Parallel(concurrency, transformer)
// writable stream that just logs whatever is written to it
const logger = new WritableStream({ write: n => console.log(n) })
await randomNumbers.pipeThrough(delayer).pipeTo(logger)
Contributing
Feel free to join in. All welcome. Please open an issue!
License
Dual-licensed under MIT + Apache 2.0