command-pool
Library for limiting parallel work.
Last updated 4 years ago by bacher .
GPL-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install command-pool 
SYNC missed versions from official npm registry.

Command-Pool

Library for limiting parallel work.

Installation:

npm install --save command-pool

Usage:

API:

Static method .start (returns a Promise):

CommandPool.start(commandArguments, [parallelCount], callback);
  • commandArguments (Array) - Array of arguments for commands or count of iterations;
  • parallelCount (Optional, Number, Default = 1) - Count of parallel work tasks;
  • callback (Function(arg, i, next)) - Function that calls on task, you must return a Promise or call next();
CommandPool.start(tasksCount, [parallelCount], callback);
  • tasksCount (Number) - Count of iterations;
  • parallelCount (Optional, Number, Default = 1) - Count of parallel work tasks;
  • callback (Function(i, next)) - Function that calls on task, you must return a Promise or call next();

Example:

var CommandPool = require('command-pool');

CommandPool.start(5, 3, function(i, next) {
    console.log('%s started', i);

    setTimeout(function() {
        console.log('%s resolved', i);
        next(null, 'OK');
    }, Math.floor(Math.random() * 2000));
}).then(function(data) {
    console.log('RESULT:', data);
}, function(error) {
    console.log('ERROR:', error);
});

Output:

0 started
1 started
2 started
0 resolved
3 started
1 resolved
4 started
3 resolved
2 resolved
4 resolved
RESULT: [ 'OK', 'OK', 'OK', 'OK', 'OK' ]

Caution:

Work only in node version >= 0.12.

Current Tags

  • 0.3.2                                ...           latest (4 years ago)

6 Versions

  • 0.3.2                                ...           4 years ago
  • 0.3.1                                ...           4 years ago
  • 0.3.0                                ...           4 years ago
  • 0.2.0                                ...           5 years ago
  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 2
Last Month 2
Dependencies (0)
None
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |