1.0.0 • Published 3 years ago

@sebowy/concurrent-array v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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.