Runnable pool manager lib: an easy way to use multi proc with node

npm install runnablepool
8 downloads in the last day
17 downloads in the last week
43 downloads in the last month

node-runnablepool Build Status

A runnable (spawn) pool lib. An easy way to use multi proc with node.

Installing runnablepool

[sudo] npm install [-g] runnablepool


Lib: inherits from Runnable class.

Create a dedicated file to run the Runnable instance. See examples/basic_runnable.js

util = require('util'),
rp = require('../lib/runnablepool'),
BasicRunnable = (function () {

        function BasicRunnable () {
            this.verbose = false;
        util.inherits(BasicRunnable, rp.Runnable); = function(config, callback){
            // Do you stuff here.
            // Once you done, just call callback function with results as params
            callback('BasicRunnable run');

        return BasicRunnable;
run = new BasicRunnable(); // class must be instanciated: it's got interfaces to be managed by the pooler.

Lib: instanciate a RunnablePool with BasicRunnable script

util = require('util'),
i = 0,
rp = require('../lib/runnablepool'),
pool = new rp.RunnablePool({
        modulePath: __dirname + '/basic_runnable.js' // Here is our Runnable script
pool.on('result', function(pid, err, result) {
        if (err) {
            if (err.stack) {
                return console.log(util.format('pid %d > %s', pid, err.stack));
            return console.log(util.format('pid: %d > Error : ', pid, err.message));
        // call pool.abort() if you do no need all other result.
        // this will interrupt the pooler.

pool.on('end', function(runnables) {
        runnables.forEach(function(runnable) {
                console.log(util.format('pid %d run count: %d',, runnable.runCount));

pool.on('error', function(error) {

for(i = 0; i < 1000; i++) {;


  • pooler: examples/basic.js
  • runnable: examples/basic_runnable.js


Just call

util = require('util'),
rp = require('../lib/runnablepool'),
BasicRunnable = (function () {
run = new BasicRunnable();; // do forget to remove it once you are done !

Run it as usual

node basic_runnable.js



* @constructor
* @param {number} config.maxRunnables: max proc to use. Default to os.cpus().length
* @param {String} config.modulePath: module path see child_process.fork params
* @param {Array} config.args: see child_process.fork params
* @param {Object} config.options: see child_process.fork params
* @param {Boolean} config.verbose: verbose mode. Default to false
* @param {Number} config.timeout: time in seconds to wait for a result before killing process. Default to 30
* Emit 'result' function({Number} pid, {Error || undefined} err, {Mixed} result) for each results
* Emit 'end' function({Array of {{Number} pid, {Number} runCount }} runnables) once all results are done
* Emit 'error' function({Error} error})
function RunnablePool (config)

* @public
* @param {Mixed} config to pass to runnable script
* This method fill the pooler
*/ = function(config)


node-runnablepool is licensed under the MIT license.

npm loves you