{"id":15414895,"url":"https://github.com/lxsmnsyc/threadpoollite","last_synced_at":"2025-04-19T12:47:55.202Z","repository":{"id":71067790,"uuid":"171842406","full_name":"lxsmnsyc/ThreadPoolLite","owner":"lxsmnsyc","description":"A library for creating Web Worker pools.","archived":false,"fork":false,"pushed_at":"2019-03-01T09:45:28.000Z","size":36,"stargazers_count":3,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-21T11:03:28.301Z","etag":null,"topics":["multi-threading","multiprocessing","multithreading","thread","thread-library","thread-pool","threading","threadpool","threads","web-worker","webworkers","worker","workers"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/lxsmnsyc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-21T09:33:49.000Z","updated_at":"2024-03-19T09:23:52.000Z","dependencies_parsed_at":"2023-02-21T23:46:35.809Z","dependency_job_id":null,"html_url":"https://github.com/lxsmnsyc/ThreadPoolLite","commit_stats":{"total_commits":21,"total_committers":1,"mean_commits":21.0,"dds":0.0,"last_synced_commit":"03c3a55714f08c0e795aa77c76be87b03605f573"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxsmnsyc%2FThreadPoolLite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxsmnsyc%2FThreadPoolLite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxsmnsyc%2FThreadPoolLite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxsmnsyc%2FThreadPoolLite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lxsmnsyc","download_url":"https://codeload.github.com/lxsmnsyc/ThreadPoolLite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241435175,"owners_count":19962400,"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":["multi-threading","multiprocessing","multithreading","thread","thread-library","thread-pool","threading","threadpool","threads","web-worker","webworkers","worker","workers"],"created_at":"2024-10-01T17:05:12.577Z","updated_at":"2025-03-01T22:32:42.823Z","avatar_url":"https://github.com/lxsmnsyc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ThreadPoolLite\nA library for creating Web Worker pools.\n\n[![npm version](https://badge.fury.io/js/threadpool-lite.svg)](https://badge.fury.io/js/threadpool-lite)[![](https://data.jsdelivr.com/v1/package/npm/threadpool-lite/badge)](https://www.jsdelivr.com/package/npm/threadpool-lite)\n## Example\n\nThe example below displays 10 random numbers per 3 seconds.\n```js\n/**\n * \n *  Create 10 Workers \n * \n */\nlet tp = new ThreadPoolLite(20); \n\n/**\n * \n *  Generate 20 tasks\n * \n *  The task is to output a random number after 3 seconds\n *  of their current runtime.\n * \n */\nfor(let i = 0; i \u003c 20; i++){\n    /**\n     * \n     *    You can use raw functions or template strings\n     *\n     */\n    tp.run(`function (){\n        /**\n         * \n         *  ThreadPoolLite workers can handle Promise\n         *  objects, neat!\n         * \n         */\n        return new Promise(function (resolve, reject){\n            setTimeout(function(){\n                resolve(`+i+`);\n            }, 3000)\n        })\n    }`).then(console.log)\n}\n```\n\nExample Output:\n```\n19\n18\n16\n15\n17\n13\n14\n8\n5\n10\n9\n4\n2\n0\n6\n1\n12\n11\n7\n3\n```\n\n## Usage\n### Loading Module\nNPM\n```bash\nnpm i threadpool-lite\n```\nCDN\n```html\n\u003cscript type=\"text/javascript\" src=\"https://cdn.jsdelivr.net/npm/threadpool-lite@1.2.2/index.min.js\"\u003e\u003c/script\u003e\n```\n\n## API\n* [ThreadPoolLite](#ThreadPoolLite)\n    * [new ThreadPoolLite(workerCount)](#new_ThreadPoolLite_new)\n    * [.run(runnable)](#ThreadPoolLite+run) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\n    * [.terminate()](#ThreadPoolLite+terminate)\n    * [.getActiveCount()](#ThreadPoolLite+getActiveCount)\n    * [.getIdleCount()](#ThreadPoolLite+getIdleCount)\n\n\u003ca name=\"new_ThreadPoolLite_new\"\u003e\u003c/a\u003e\n\n### new ThreadPoolLite(workerCount)\nCreate a pool of workers, defaults to the amount of logical cores \nyour hardware has.\n\n\n| Param | Type |\n| --- | --- |\n| workerCount | \u003ccode\u003eInteger\u003c/code\u003e | \n\n\u003ca name=\"ThreadPoolLite+run\"\u003e\u003c/a\u003e\n\n### threadPoolLite.run(runnable) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\nRuns(or enqueues, if no idle workers are available) a task.\n\nTasks have scope of their own, and cannot access their parent scope.\n\n**Kind**: instance method of [\u003ccode\u003eThreadPoolLite\u003c/code\u003e](#ThreadPoolLite)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| runnable | \u003ccode\u003efunction\u003c/code\u003e | the task the worker receives |\n\n\u003ca name=\"ThreadPoolLite+terminate\"\u003e\u003c/a\u003e\n\n### threadPoolLite.terminate()\nTerminates all workers\n\n**Kind**: instance method of [\u003ccode\u003eThreadPoolLite\u003c/code\u003e](#ThreadPoolLite)  \n\u003ca name=\"ThreadPoolLite+getActiveCount\"\u003e\u003c/a\u003e\n\n### threadPoolLite.getActiveCount()\nGet the active workers count\n\n**Kind**: instance method of [\u003ccode\u003eThreadPoolLite\u003c/code\u003e](#ThreadPoolLite)  \n\u003ca name=\"ThreadPoolLite+getIdleCount\"\u003e\u003c/a\u003e\n\n### threadPoolLite.getIdleCount()\nGet the idle workers count\n\n**Kind**: instance method of [\u003ccode\u003eThreadPoolLite\u003c/code\u003e](#ThreadPoolLite)\n\n## Changelogs\n* 1.2.2\n    * Fixed worker workload double-free\n* 1.2.1\n    * Fixed worker error handling\n* 1.2.0\n    * Proper error handling\n* 1.1.0\n    * Run method now returns a Promise.\n* 1.0.0\n    * Initial release\n\n## License\nMIT License\n\nCopyright (c) 2019 Alexis Munsayac\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flxsmnsyc%2Fthreadpoollite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flxsmnsyc%2Fthreadpoollite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flxsmnsyc%2Fthreadpoollite/lists"}