{"id":28969966,"url":"https://github.com/varvolta/threadman","last_synced_at":"2025-08-31T03:37:30.121Z","repository":{"id":47388131,"uuid":"516096208","full_name":"varvolta/threadman","owner":"varvolta","description":"Worker threads made easy","archived":false,"fork":false,"pushed_at":"2022-09-17T23:03:18.000Z","size":123,"stargazers_count":18,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-29T22:44:20.233Z","etag":null,"topics":["nodejs","process","spawn","threads","worker"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/varvolta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-20T18:38:17.000Z","updated_at":"2024-03-20T18:36:19.000Z","dependencies_parsed_at":"2022-09-19T13:10:25.312Z","dependency_job_id":null,"html_url":"https://github.com/varvolta/threadman","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/varvolta/threadman","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/varvolta%2Fthreadman","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/varvolta%2Fthreadman/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/varvolta%2Fthreadman/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/varvolta%2Fthreadman/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/varvolta","download_url":"https://codeload.github.com/varvolta/threadman/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/varvolta%2Fthreadman/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272935835,"owners_count":25018156,"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","status":"online","status_checked_at":"2025-08-31T02:00:09.071Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["nodejs","process","spawn","threads","worker"],"created_at":"2025-06-24T10:12:29.899Z","updated_at":"2025-08-31T03:37:30.106Z","avatar_url":"https://github.com/varvolta.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"```\n _   _                        _\n| | | |                      | |\n| |_| |__  _ __ ___  __ _  __| |_ __ ___   __ _ _ __\n| __| '_ \\| '__/ _ \\/ _` |/ _` | '_ ` _ \\ / _` | '_ \\\n| |_| | | | | |  __/ (_| | (_| | | | | | | (_| | | | |\n \\__|_| |_|_|  \\___|\\__,_|\\__,_|_| |_| |_|\\__,_|_| |_|\n ```\n\n\u003cbr /\u003e\n\n### **Still in early stages of development. Email me any suggestions you have on varvolta@gmail.com**\n\n\u003cbr /\u003e\n\n# **Worker threads made easy.**\n\n\u003cbr /\u003e\n\nCreate and execute tasks in real cpu threads in NodeJS. (ES6 imports for now)\n\nThreadman doesn't use any dependencies. It's based on workers.\n\n\u003cbr /\u003e\n\n# Installation\n```\nnpm i threadman\n```\n\n\n\u003cbr /\u003e\n\n# Syntax\n\n```js\nnew Thread(fn, args, options?, priority?).run(callback)\n```\n\n\u003cbr /\u003e\n\n# Basic usage\n\n```js\nimport { Thread } from 'threadman'\n\nlet number = 10\n\nconst fn = (number) =\u003e number + 20\nconst args = [number]\nconst callback = (result) =\u003e number = result\n\nnew Thread(fn, args).run(callback)\n```\n\n'fn' runs in a sandbox and returns the result in callback. After you get the result you can access the main scope again and reassign variables. 'fn' can be async.\n\n\n\u003cbr /\u003e\n\n# Using modules\n\n```js\nimport { Thread } from 'threadman'\nimport md5 from 'md5'\n\nlet string\n\nconst fn = (md5, string) =\u003e md5(string)\nconst args = [md5, string]\nconst callback = (result) =\u003e string = result\n\nnew Thread(fn, args).run(callback)\n```\n\u003cbr /\u003e\n\n# Using pools\n\n```js\nimport { Thread, Pool } from 'threadman'\nimport md5 from 'md5'\n\nlet data\n\nconst fn = (md5, string) =\u003e md5(string)\nconst args = [md5, string]\nconst callback = (results) =\u003e data = results\n\nconst pool = new Pool()\n\nconst thread1 = new Thread(fn, args)\nconst thread2 = new Thread(fn, args)\n\npool.queue(thread1)\npool.queue(thread2)\n\npool.run(callback)\n```\nCallback returns all the results from thread runs in an array\n\n\n\u003cbr /\u003e\n\n# Catching errors\n\n```js\nnew Thread(fn, args).run(runCallback).catch(catchCallback)\n```\n\n\n\u003cbr /\u003e\n\n# Config\n\n```js\nimport { Dispatcher } from 'threadman'\n\n// Sets maximum parallel threads count.\n// Defaults to system with 'os.cpus().length'\nDispatcher.config.threads.maxParallel = os.cpus().length\n\n// Automatically stops the thread after returning the result.\n// Defaults to 'true'.\nDispatcher.config.autoStop = true\n\n// Enables thread logs.\n// Defaults to 'false'.\nDispatcher.config.logs.enabled = false\n\n// Sets the logger.\n// Defaults to 'console'\nDispatcher.config.logs.logger = console\n```\n\n\u003cbr/\u003e\n\n# **Events**\n\n\u003cbr/\u003e\n\n### **Subscribing to events**\n\n\u003cbr/\u003e\n\n```js\nconst thread = new Thread(fn, args)\n\nthread.on('start', onStartFn)\nthread.on('stop', onStopFn)\nthread.on('done', onDoneFn)\nthread.on('error', onErrorFn)\n\nthread.run(callback)\n```\n\n\u003cbr/\u003e\n\n### **Unsubscribe with**\n\n\u003cbr/\u003e\n\n```js\nthread.off('start', onStartFn)\nthread.off('stop', onStopFn)\nthread.off('done', onDoneFn)\nthread.off('error', onErrorFn)\n```\n\n\u003cbr/\u003e\n\n### **Unsubscribe from all events**\n\n\u003cbr/\u003e\n\n```js\nthread.offAll()\n```\n\n\u003cbr/\u003e\n\n### **Documentation to be filled more soon**","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvarvolta%2Fthreadman","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvarvolta%2Fthreadman","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvarvolta%2Fthreadman/lists"}