{"id":16646426,"url":"https://github.com/mohasarc/workers-pool","last_synced_at":"2026-04-28T20:38:17.281Z","repository":{"id":47745096,"uuid":"286136681","full_name":"mohasarc/workers-pool","owner":"mohasarc","description":"Utilizing the power of multithreading to process heavy tasks on nodejs","archived":false,"fork":false,"pushed_at":"2021-08-15T11:46:03.000Z","size":963,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-30T07:48:40.564Z","etag":null,"topics":["multithreading","nodejs","thread-pool","worker-pool","worker-threads"],"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/mohasarc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-08T23:49:17.000Z","updated_at":"2021-11-14T23:04:32.000Z","dependencies_parsed_at":"2022-07-22T02:18:20.713Z","dependency_job_id":null,"html_url":"https://github.com/mohasarc/workers-pool","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/mohasarc/workers-pool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohasarc%2Fworkers-pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohasarc%2Fworkers-pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohasarc%2Fworkers-pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohasarc%2Fworkers-pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mohasarc","download_url":"https://codeload.github.com/mohasarc/workers-pool/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohasarc%2Fworkers-pool/sbom","scorecard":{"id":656723,"data":{"date":"2025-08-11","repo":{"name":"github.com/mohasarc/workers-pool","commit":"97edb2ac8ee43f809449fa0b985703e719211cfb"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.7,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 1/22 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/node.js.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":3,"reason":"dependency not pinned by hash detected -- score normalized to 3","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/mohasarc/workers-pool/node.js.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/mohasarc/workers-pool/node.js.yml/master?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   1 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 10 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"21 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-21T14:53:41.107Z","repository_id":47745096,"created_at":"2025-08-21T14:53:41.107Z","updated_at":"2025-08-21T14:53:41.107Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32399002,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T19:38:08.556Z","status":"ssl_error","status_checked_at":"2026-04-28T19:37:55.688Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["multithreading","nodejs","thread-pool","worker-pool","worker-threads"],"created_at":"2024-10-12T08:27:35.504Z","updated_at":"2026-04-28T20:38:17.233Z","avatar_url":"https://github.com/mohasarc.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# workers-pool\nCreating truly asynchronus functions has never been easier!  \n      \n![npm](https://img.shields.io/npm/dt/workers-pool)\n![NPM](https://img.shields.io/npm/l/workers-pool)\n![npm](https://img.shields.io/npm/v/workers-pool)\n    \nThe `workers-pool` package allows you to easily create a pool of workers, pass them\nsome heavy tasks in the form of functions, and use the generated async function as \nasynchronous Promise-based functions.\n\n**Important note 1:** This is not yet fully tested, so be careful while using it!  \n**Important note 2:** Currently there is supports for only node environment!\n\n## Installing the package\n```js\nnpm i workers-pool\n```\n\n## Usage\n### Adding `TaskRunners` statically    \n\n`functions.js`\n```js\nconst { Pool } = require('workers-pool');\nconst {isMainThread} = require('worker_threads');\n\n// Some function to be made asynchronous\nfunction add (a, b) {\n    return a + b;\n}\n\nfunction sub (a, b) {\n    return a - b;\n}\n\n// Step 1: export the functions\nmodule.exports.add = add;\nmodule.exports.sub = sub;\n\nif (isMainThread){\n    // Step 2: create a pool (can create a \n    // separate pool for separate functions)\n    const myPool = new Pool({\n        taskRunners: [\n            {name: 'add', job: add, threadCount: 4, lockToThreads: true},\n            {name: 'sub', job: sub, threadCount: 4, lockToThreads: true},\n        ],\n        totalThreadCount: 8,\n    });\n\n    // Step 3: generate the async version of the functions\n    let addAsync = myPool.getAsyncFunc('add');\n    let subAsync = myPool.getAsyncFunc('sub');\n\n    // Step 4: export the new async functions\n    module.exports.addAsync = addAsync;\n    module.exports.subAsync = subAsync;\n    module.exports.myPool = myPool;\n}\n```\n\n`index.js`\n```js\nconst {addAsync, subAsync, myPool} = require('./functions.js')\n    \nasync function test() {\n    try {\n        let result = await addAsync(2, 5);\n        console.log(result); // output: 7\n    } catch (error) {\n        console.log(error);\n    }\n\n    try {\n        let result = await subAsync(100, 10);\n        console.log(result) // output: 90\n    } catch (error) {\n        console.log(error);\n    }\n}\n\ntest().then(() =\u003e {\n    myPool.terminate();\n});\n```\nNote `isMainThread` is essential to defferentiate whether a file is being run in the main \nthread or a worker thread, so it can be used to prevent certain parts of the code, especially \npool and async functions creation, from being recursively run as shown in the example.\n\n### Adding `TaskRunners` dynamically\nTo allow dynamical addition of functions to workers, you only to enable the option of `allowDynamicTaskRunnerAddition`.\n\nYou can still have static ones, but make sure that the `totalThreadCount` is more than the sume of `threadCount` of each static `taskRunner` since they can cause a starvation for the dynamic ones.\n\n`index.js`\n```js\nconst { Pool } = require('workers-pool');\nconst {isMainThread} = require('worker_threads');\n\n// Some function to be made asynchronous\nfunction mul (a, b) {\n    return a * b;\n}\n\nfunction add (a, b) {\n    return a + b;\n}\n\nfunction sub (a, b) {\n    return a - b;\n}\n\n// Export the functions\nmodule.exports.add = add;\nmodule.exports.sub = sub;\nmodule.exports.mul = mul;\n\nif (isMainThread) {\n    // Create the pool with some static TaskRunners (if wanted)\n    const myPool = new Pool({\n        taskRunners: [\n            {name: 'add', job: add, threadCount: 2, lockToThreads: true}, // Static\n            {name: 'sub', job: sub, threadCount: 2, lockToThreads: true}, // Static\n        ],\n        totalThreadCount: 5,\n        allowDynamicTaskRunnerAddition: true,\n    });\n    \n    // Then finally, to add a dynamic TaskRunner call addTaskRunner(TaskRunner[])\n    myPool.addTaskRunner({name: 'multiply', job: mul}); // Dynamic\n    let mulAsync = myPool.getAsyncFunc('multiply');\n\n    // Use the async function\n    mulAsync(2, 5).then((answer) =\u003e {\n        console.log(answer);\n    });\n}\n```\n\n### Difference between static and dynamic TaskRunners     \nThe dynamic `TaskRunnres` are not bound to a worker thread; therefore, at every call to the generated \nasync function corresponding to them, they are required by a different thread and executed there.\n\nThe static `TaskRunners` on the other hand, they are required by the worker thread at its instantiation and\nthey are bound to it.\n\nAs a result, we can have more of the dynamic `TaskRunners` with a smaller number of threads; however, static `TaskRunners`\nexecute faster since there is no overhead of requiring the function everytime we try to execute the generated async function\ncorresponfing to it.\n\n### Stats\nYou can also get the statistics of the pools:\n```js\nconst Pool = require('workers-pool');\n\nPool.stats();     // brief info about the pools\nPool.stats(true); // Verbose info about the pools\n```\n\n### terminate\nYou can terminate all the threads in the pool at once by calling:\n```js\nmyPool.terminate(true);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohasarc%2Fworkers-pool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohasarc%2Fworkers-pool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohasarc%2Fworkers-pool/lists"}