npm.io
5.0.9 • Published 1 month ago

maximize-iterator

Licence
MIT
Version
5.0.9
Deps
2
Size
50 kB
Vulns
0
Weekly
0
Stars
1

maximize-iterator

Maximize the parallel calls of an iterator supporting asyncIterator interface.

npm install maximize-iterator
const maximize = require('maximize-iterator');

async function* values() {
  yield* [1, 2, 3, 4];
}

async function main() {
  const results = [];
  await maximize(values(), (value) => results.push(value), { concurrency: 2 });
  console.log(results); // [1, 2, 3, 4]
}

main().catch(console.error);

Options

  • bool: callbacks - use an each function with a callback function(entry, callback) (default: false)
  • function: error - handle iterator or item errors. Return true to stop processing (default: stop on error).
  • function: canProcess - return false to pause requesting more iterator values (default: always process).
  • number: concurrency - parallelism of processing. (default: 4096)
  • number: limit - maximum number to process. (default: Infinity)

Keywords