JSPM

@vitalyostanin/mutex-pool

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 37
  • Score
    100M100P100Q72930F
  • License ISC

Simple workers pool using async mutex

Package Exports

  • @vitalyostanin/mutex-pool
  • @vitalyostanin/mutex-pool/dist/index.js
  • @vitalyostanin/mutex-pool/dist/index.mjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@vitalyostanin/mutex-pool) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Simple workers pool using async mutex

Inspired by module async-mutex.

Usage

npm install --save @vitalyostanin/mutex-pool
import { MutexPool } from "@vitalyostanin/mutex-pool";

// ...

const pool = new MutexPool(3);

for await (const jobData of asyncInputIterator) {
  const job = () => console.log('jobData', { jobData } );

  await pool.start(job);
}

await pool.allJobsFinished();

// ...

Why not something

Just for fun - this is the main reason.

p-limit

I know the only way to wait for all jobs to finish:

await Promise.all(limitedFnList);

But in my case there is no limitedFnList and I don't want to build it from async input generator.

p-ratelimit

You can use mutex-pool in combination with p-ratelimit, where mutex-pool is responsible of consuming input and p-ratelimit is responsible of calling external resources.