# lib-promise-pool

> A nodejs library for executing the job concurrently while controlling the rate of concurrency

Latest version **1.1.0** (published 2023-04-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install lib-promise-pool
pnpm add lib-promise-pool
yarn add lib-promise-pool
bun add lib-promise-pool
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2023-04-30 |
| First published | 2018-10-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 10.0.0 |
| Dependencies | 3 |
| Unpacked size | 12.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | 001akashbabu@gmail.com |
| Maintainers | akashbabu |

## Links

- npm: https://www.npmjs.com/package/lib-promise-pool
- Repository: https://github.com/AkashBabu/lib-promise-pool
- Homepage: https://github.com/AkashBabu/lib-promise-pool#readme
- Issues: https://github.com/AkashBabu/lib-promise-pool/issues
- npm.io page: https://npm.io/package/lib-promise-pool

## Dependencies (3)

- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.26.0
- [babel-polyfill](https://npm.io/package/babel-polyfill.md) ^6.26.0
- [chai-as-promised](https://npm.io/package/chai-as-promised.md) ^7.1.1

## Recent versions

- 1.1.0 (latest) — 2023-04-30
- 1.0.1 — 2019-02-07
- 1.0.0 — 2018-10-03

## README

# lib-promise-pool
A nodejs library for executing the job concurrently while controlling the rate of concurrency

## Installation
> npm i lib-promise-pool -S

## Sample Usage
```js
import PromisePool from 'lib-promise-pool'

async function worker(d, i) {
    // console.log(d, i) //=> 1,1    2,2   3,3
    return new Promise(res => setTimeout(() => res(d), d * 1000));
}

const data = [1, 2, 3];

const start = Date.now();
await PromisePool(data, worker, 1);
const end = Date.now();

const diff = end - start

console.log(diff) // 6

// If concurrency is changed to 2
console.log(diff) // 4

// If concurrency is changed to 3
console.log(diff) // 3

```

## Documentation
**PromisePool(array, worker, concurrency=1, options = {stopOnErr: false})**   

| Param                 | Description   |
| :-------------------- | :-----------  |
| `array`               | Array containing input data to worker |
| `worker`              | Async worker function |
| `concurrency`         | Number of concurrent jobs to be executed |
| `options`             | Options for controlling the execution of jobs |
| `options.stopOnErr`   | Whether to stop executing the rest of the promises if a failure is detected. *Defaults to false* |


## Test
> npm run test

## Coverage Report
> npm run coverage

## Contributions
This is open-source, which makes it obvious for any PRs, but I would request you to add necessary test-cases for the same

---
_Source: https://npm.io/package/lib-promise-pool · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
