0.1.5 • Published 3 years ago

promise-commander v0.1.5

Weekly downloads
1
License
GPL-2.0
Repository
github
Last release
3 years ago

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);
0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago