{"id":17749486,"url":"https://github.com/oresoftware/poolio","last_synced_at":"2025-06-18T03:37:20.920Z","repository":{"id":57327369,"uuid":"44147054","full_name":"ORESoftware/poolio","owner":"ORESoftware","description":"Node.js / NPM module for creating custom worker pools using child processes.","archived":false,"fork":false,"pushed_at":"2018-10-03T06:47:19.000Z","size":333,"stargazers_count":8,"open_issues_count":6,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-18T16:54:45.323Z","etag":null,"topics":["affinity-propagation","child-process","cluster","nodejs","npm","pool","worker-pool","workers"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ORESoftware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-13T02:34:15.000Z","updated_at":"2024-11-16T04:38:39.000Z","dependencies_parsed_at":"2022-09-13T19:00:36.343Z","dependency_job_id":null,"html_url":"https://github.com/ORESoftware/poolio","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ORESoftware/poolio","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ORESoftware%2Fpoolio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ORESoftware%2Fpoolio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ORESoftware%2Fpoolio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ORESoftware%2Fpoolio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ORESoftware","download_url":"https://codeload.github.com/ORESoftware/poolio/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ORESoftware%2Fpoolio/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260483626,"owners_count":23016085,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["affinity-propagation","child-process","cluster","nodejs","npm","pool","worker-pool","workers"],"created_at":"2024-10-26T11:23:30.588Z","updated_at":"2025-06-18T03:37:15.908Z","avatar_url":"https://github.com/ORESoftware.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Poolio\n\n[![Build Status](https://travis-ci.org/ORESoftware/poolio.svg?branch=master)](https://travis-ci.org/ORESoftware/poolio)\n\n\n##  =\u003e a versatile process pool for Node.js\n\n* create a pool of N workers\n* define the start script for each worker in the pool\n* kill workers after each task and automatically generate a new worker on exit, or more likely, reuse the same\nworkers for the lifecycle of the worker pool.\n* dynamically add or remove workers at will\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n\u003ca href=\"https://nodei.co/npm/poolio/\"\u003e\u003cimg src=\"https://nodei.co/npm/poolio.png?downloads=true\u0026downloadRank=true\u0026stars=true\"\u003e\u003c/a\u003e\n\n\u003cbr\u003e\n\u003cbr\u003e\n\nThis module behaves much like these two pre-existing modules:\n\n* core: https://nodejs.org/api/cluster.html#cluster_cluster_setupmaster_settings\n* userland: https://github.com/thisandagain/fork-pool\n\nThis module strives for a better implementation and simpler API. Like the above,\nthis lib utilizes a child_process pool, using child_process.fork() like so: \n\n\n```javascript\n\nconst cp = require('child_process');\nconst n = cp.spawn('node',['\u003cyour-worker-script\u003e']);\n\n```\n\n## Installation\n\n```bash\nnpm install -S poolio\n```\n\n## Basic Use\n\n```js\n\nconst {Pool} = require('poolio');\n\n// in the current process, we initialize a pool\nconst pool = new Pool({\n    filePath: 'child.js',    //path is relative to root of your project, but it's best to pass in an absolute path\n    size: 3\n});\n\n\nfunction rankPostsUsingWorkerPool(postIds){\n\n   return pool.anyp({action: 'run', posts: postIds})\n    .then(function(){\n        log.info('successfully processes post ranking.');\n    })\n    .catch(function (err) {\n        log.error(err);\n    });\n    \n}\n       \n\n// in a child process - simple example\n\nprocess.on('message', function (data) {   //use the closure, it is better that way\n\n    const workId = data.workId;\n    \n    var result;\n    \n    try{\n    \n     result = doSomeIntensiveWork();\n     \n     process.send({\n        msg: 'done/return/to/pool',\n        error: null,\n        workId: workId,\n        result: result\n     });\n     \n    }\n    catch(err){\n        process.send({\n            msg: 'error',\n            error: err.stack,\n            workId: workId,\n            result: null\n         });\n    }\n    \n    \n    \n    function doSomeIntensiveWork(){\n    \n       // ....\n    \n        return 'some-very-special-result';\n    \n    }\n    \n    \n});\n\n\n```\n\n## Advanced use\n\n```js\n\n// in the parent process, we require the module and initialize a pool\n\nconst Pool = require('poolio');\n\nconst pool = new Pool({\n    filePath: 'child.js',    //path is relative to root of your project\n    size: 5\n});\n\n\nfunction doHeavyDataIntensiveAsyncWork(data){\n    return pool.anyp({action: 'all', data: data}); // return the promise\n}\n       \n\n// in a child process - advanced example\n\nconst _ = require('lodash');\nconst domain = require('domain');\n\n\nprocess.on('message', function (data) {   //use the closure, it is better that way\n\n    const workId = data.workId;\n    const d = domain.create();\n    \n    d.once('error', function(err){\n       this.exit();\n       process.send({\n         msg: 'error',\n         error: err.stack,\n         workId: workId,\n         result: null\n       });\n    \n    });\n    \n    d.run(function(){\n    \n    const actions = [];\n    \n    switch(data.action){\n    \n         case 'foo':\n           actions.push(foo);\n           break;\n         case 'bar':\n           actions.push(bar);\n           break;\n         case 'baz':\n           actions.push(baz);\n           break;\n         case 'all':\n           actions.push(foo);\n           actions.push(bar);\n           actions.push(baz);\n           break;\n         default:\n           throw new Error('No case matched'); //will be caught by domain.on('error')\n    \n    }\n    \n    \n       Promise.all(actions).then(function(result){\n       \n           process.send({\n              msg: 'done/return/to/pool',\n              result: result,\n              workId: workId\n              error: null\n           });\n    \n       });\n    \n    \n    });\n    \n    function foo(){\n       \n       return new Promise(function(resolve,reject){\n       \n            // ....do some async work...\n        \n       })\n       \n    }\n    \n    \n    function bar(){\n    \n        return new Promise(function(resolve,reject){\n             \n            // ....do some async work...\n              \n        })\n    \n    }\n    \n    function baz(){\n    \n       return new Promise(function(resolve,reject){\n              \n           // ....do some async work...\n               \n       })\n    }\n    \n    \n});\n\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foresoftware%2Fpoolio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foresoftware%2Fpoolio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foresoftware%2Fpoolio/lists"}