map-stream-2-limited

Build a limited concurrency through2 stream from an async function

Usage no npm install needed!

<script type="module">
  import mapStream2Limited from 'https://cdn.skypack.dev/map-stream-2-limited';
</script>

README

map-stream-2-limited

Limited concurrency map-stream implementation. Inspired by map-stream-limit but built on through2 and additionally allows the concurrency to be changed after instantiation.

Somewhat experimental and likely to be caught out by edge cases...

Install

$ npm install map-stream-2-limited

Usage

var mapLimited = require('map-stream-2-limited')
var transform = mapLimited(function (data, callback) {
  callback(null, data)

  // or

  callback(new Error('something failed'))

}, 10) // initial concurrency limit of 10

someStream
.pipe(transform)

// Modify concurrency limit by supplying a transform function
transform.changeLimit(function (limit) {
  return limit + 1 // Will throw if you attempt to change the limit to < 1
})

License

MIT

© Jon Merrifield