@sebowy/concurrent-array

"ConcurrentArray" - Run array higher order functions asynchronously with concurrency control

Usage no npm install needed!

<script type="module">
  import sebowyConcurrentArray from 'https://cdn.skypack.dev/@sebowy/concurrent-array';
</script>

README

ConcurrentArray

Run array higher order functions asynchronously with concurrency control

npm latest version Build states semantic-release

Installation

npm install --save @sebowy/concurrent-array
# or
yarn add @sebowy/concurrent-array

Usage

Examples

  • async sorting
import { ConcurrentArray } from "@sebowy/concurrent-array";

const array = [3, 5, 1, 2, 4];
const asyncArray = new ConcurrentArray(array, {
  maxConcurrency: 10,
});
asyncArray
  .sort((left, right) => new Promise((resolve) => setTimeout(() => resolve(left - right), 1000)), {
    maxConcurrency: 5, // overwrite max concurrency for sort array operation
  })
  .then(console.log);

will produce:

[1, 2, 3, 4, 5]

respecting allowed maximum concurrency.

Learn more

Please refer to @sebowy/concurrent-queue and @sebowy/async-array README files to learn more about possible options and methods.