{"id":17113862,"url":"https://github.com/potatoparser/thread-process","last_synced_at":"2026-01-19T06:01:52.777Z","repository":{"id":34013077,"uuid":"164766277","full_name":"PotatoParser/thread-process","owner":"PotatoParser","description":"Multi-threading wrapper around NodeJS Cluster API","archived":false,"fork":false,"pushed_at":"2022-11-10T00:46:09.000Z","size":306,"stargazers_count":1,"open_issues_count":4,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-27T21:49:00.679Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","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/PotatoParser.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}},"created_at":"2019-01-09T01:53:42.000Z","updated_at":"2020-10-06T22:41:10.000Z","dependencies_parsed_at":"2023-01-15T03:57:23.781Z","dependency_job_id":null,"html_url":"https://github.com/PotatoParser/thread-process","commit_stats":null,"previous_names":["potatoparser/threadprocess"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/PotatoParser/thread-process","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PotatoParser%2Fthread-process","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PotatoParser%2Fthread-process/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PotatoParser%2Fthread-process/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PotatoParser%2Fthread-process/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PotatoParser","download_url":"https://codeload.github.com/PotatoParser/thread-process/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PotatoParser%2Fthread-process/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28562237,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T03:31:16.861Z","status":"ssl_error","status_checked_at":"2026-01-19T03:31:15.069Z","response_time":67,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["hacktoberfest"],"created_at":"2024-10-14T17:13:06.418Z","updated_at":"2026-01-19T06:01:52.761Z","avatar_url":"https://github.com/PotatoParser.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Thread Process](https://github.com/PotatoParser/threadProcess/blob/master/thread-process.png?raw=true)\n[![Build Status](https://api.travis-ci.com/PotatoParser/thread-process.svg?branch=master)](https://travis-ci.com/PotatoParser/thread-process)\n\nSimple Threading with JS through NodeJS Cluster\n```javascript\nconst thread = require(\"thread-process\");\n\nfunction temp() {\n    console.log(\"Hello World ~Thread\");\n}\n\nconst thr = new Thread();\nthr.store(temp);\nthr.run();\nthr.close();\n```\n# Table of Contents\n+ [Features](#features)\n+ [Installing](#installing)\n+ [Initializing](#initializing)\n+ [Properties](#properties)\n+ [Thread Class](#thread-class)\n\t+ [Constructor](#constructor)\n\t+ [Storing functions](#storing-functions-asynchronous)\n\t+ [Global Variables Accessible](#global-constiables-accessible)\n\t+ [Running Functions](#running-functions-asynchronous)\n\t+ [Running Multiple Threads](#running-multiple-threads-asynchronous)\n    + [Events](#events)\n\t+ [Closing Threads](#closing-threads)\n+ [Immediate Thread](#immediate-thread-asynchronous)\n+ [Example Usage](#example-usage)\n\n# Features\n+ Supports \"require\" in \"threaded\" functions\n+ Supports storing both synchronous and asynchronous functions\n+ Multiple threads running simultaneously\n+ Thread emitted events\n+ Thread cleanup\n\n# Installing\nRequires prior installation of NodeJS\n```\n$ npm install thread-process\n```\n# Initializing\n```javascript\nconst thread = require(\"thread-process\");\n```\n# Properties\n```javascript\nThread.MAX_THREADS // Gets the maximum CPU count\nThread.OPEN_THREADS // Gets the count of how many threads are active\n```\n# Thread Class\n## Constructor\n```javascript\nnew Thread(); // Constructing a thread with default settings\nnew Thread(function); // Stores a function\n```\n## Storing Functions *(Asynchronous)*\n*(Async) returns the function stored*\n```javascript\nthr.store(function);\nthr.store(function, function.name); // Override the function name or provide one that is missing\n```\n## Global Variables Accessible\n```javscript\nTHREAD_DATA // (Object) Contains all the functions stored\nFOCUSED_FUNCTION // (String) The most recent function\nRETURN(data); // Sends data from the function to the main thread\n```\n## Running Functions *(Asynchronous)*\nRun the most recent function stored or executed by the thread\n\n*(Async) returns the data returned by the function executed*\n```javascript\nthr.run();\nthr.runOnce(); // Closes the thread after running\n```\nRun target function stored in the thread\n```javascript\nthr.run(\"temp\"); // Runs temp()\n```\nRun with arguments\n```javascript\nthr.run(function.name, [arg1,arg2,arg3]) // temp(arg1, arg2, arg3)\nthr.run([arg1,arg2,arg3])\n```\n## Running Multiple Threads *(Asynchronous)*\n\n*(Async) returns data as an Array*\n```javascript\nThread.runAll(thr.run(), ...);\n```\n## Events\nEvent handling can make life much easier!\n```javascript\nthr.on(\"completed\", (data)=\u003e{}); // Contains the returned data\nthr.on(\"returned\", (data)=\u003e{}); // Contains data returned by RETURN(data);\n```\n## Closing Threads\n```javascript\nthr.close();\n```\n# Immediate Thread *(Asynchronous)*\nRuns a function within a thread and immediately closes the thread upon completion\n\n*(Async) returns the data returned by the function executed*\n```javascript\nThread.exec(function);\nThread.exec(function, [arg1,arg2,arg3]);\n```\n# Example Usage\nUsing thread constiables\n```javascript\nconst temp = (text)=\u003e{\n    console.log(THREAD_DATA);\n    console.log(FOCUSED_FUNCTION); // Outputs \"temp\"\n}\nasync function main(){\n    const tp = new Thread();\n    await tp.store(temp);\n    await tp.runOnce();\n}\nmain();\n```\nAsynchronous management of threads \u0026 passing values\n```javascript\nconst temp = async (text)=\u003e{\n    console.log(`Async! ${text}`);\n}\nasync function main(){\n    const tp = new Thread();\n    await tp.store(temp);\n    await tp.runOnce([\"~ Thread\"]);\n}\nmain();\n```\nMultiple stored functions\n```javascript\nconst func1 = ()=\u003e{console.log(\"First function!\")}\nconst func2 = ()=\u003e{console.log(\"Second function!\")}\nasync function main(){\n    const tp = new Thread();\n    await tp.store(func1);\n    await tp.store(func2);\n    await tp.runOnce(\"func1\");\n}\nmain();\n```\nUsing **then** instead of async/await\n```javascript\nconst temp = ()=\u003e{console.log(\"Hello World!\")}\nconst tp = new Thread();\ntp.store(temp).then((result)=\u003e{tp.runOnce();});\n```\nRunning simultaneous threads\n```javascript\nconst temp = ()=\u003e{return \"Hello\";}\nconst tp = new Thread(temp);\nconst tp2 = new Thread(temp);\nThread.runAll(tp.runOnce(), tp.runOnce()).then((result)=\u003econsole.log(result));\n```\nRunning with events\n```javascript\nconst temp = ()=\u003e{RETURN(\"Hello\")};\nconst tp = new Thread(temp);\ntp.on(\"returned\", (data)=\u003e{\n    console.log(data);\n    tp.close();\n});\ntp.run();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpotatoparser%2Fthread-process","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpotatoparser%2Fthread-process","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpotatoparser%2Fthread-process/lists"}