promise-commander

0.1.5 • Public • Published

Promise-Commander

Library for limiting parallel work.

Installation:

npm install --save promise-commander

Usage:

PC has 3 groups of method (parallel, limit, series), each group contains "each" and "map" variant.

API:

each Perform parallel task execution
map Perform parallel task execution and return results

PC.each(tasks, iterationCallback).then(() => ...);
PC.map(tasks, iterationCallback).then(results => ...);
  • tasks (Array) - Array of arguments for commands;
  • iterationCallback: (arg, i) => *|Promise - Function that calls on task;

eachLimit Perform parallel task execution with worker limit
mapLimit Perform parallel task execution with worker limit and return results

PC.eachLimit(tasks, parallelCount, iterationCallback).then(() => ...);
PC.mapLimit(tasks, parallelCount, iterationCallback).then(results => ...);
  • tasks (Array) - Array of arguments for commands;
  • parallelCount (number) - Count of parallel work tasks;
  • iterationCallback (arg, i) => *|Promise - Function that calls on task;

eachSeries Perform sequential task execution
mapSeries Perform sequential task execution and return results

PC.eachSeries(tasks, iterationCallback).then(() => ...);
PC.mapSeries(tasks, iterationCallback).then(results => ...);
  • tasks (Array) - Array of arguments for commands;
  • iterationCallback (arg, i) => *|Promise - Function that calls on task;

Example:

const PC = require('promise-commander');

const results = await PC.mapLimit(['john', 'pepe', 'nick', 'mark'], 2, async (value) => {
    await someAsyncAction();
    return `Hello ${value}`;
});

console.log('Processing is done, results:', results);

Readme

Keywords

Package Sidebar

Install

npm i promise-commander

Weekly Downloads

6

Version

0.1.5

License

GPL-2.0

Unpacked Size

5.23 kB

Total Files

3

Last publish

Collaborators

  • bacher