Socket
Book a DemoInstallSign in
Socket

lib-promise-pool

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lib-promise-pool

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

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

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

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})

ParamDescription
arrayArray containing input data to worker
workerAsync worker function
concurrencyNumber of concurrent jobs to be executed
optionsOptions for controlling the execution of jobs
options.stopOnErrWhether 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

FAQs

Package last updated on 30 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts