{"id":19408670,"url":"https://github.com/morglod/simple-multithread-js","last_synced_at":"2025-09-02T13:08:00.940Z","repository":{"id":114476247,"uuid":"123509641","full_name":"Morglod/simple-multithread-js","owner":"Morglod","description":null,"archived":false,"fork":false,"pushed_at":"2018-03-02T00:39:53.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-25T02:17:37.066Z","etag":null,"topics":["mutlithreading"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Morglod.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-03-02T00:39:30.000Z","updated_at":"2018-08-29T14:28:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"f54d3260-257a-42f6-9c5e-ce79d9c50b38","html_url":"https://github.com/Morglod/simple-multithread-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Morglod/simple-multithread-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morglod%2Fsimple-multithread-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morglod%2Fsimple-multithread-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morglod%2Fsimple-multithread-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morglod%2Fsimple-multithread-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Morglod","download_url":"https://codeload.github.com/Morglod/simple-multithread-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morglod%2Fsimple-multithread-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273287679,"owners_count":25078575,"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-09-02T02:00:09.530Z","response_time":77,"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":["mutlithreading"],"created_at":"2024-11-10T12:07:22.026Z","updated_at":"2025-09-02T13:08:00.905Z","avatar_url":"https://github.com/Morglod.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simple-multithread\n\nBased on [Web Workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) supported by [all modern browsers](https://caniuse.com/#feat=webworkers).\n\nTypeScript-ready.\n\n## Example 1\n\nMultithreading is simple\n\n```js\nasync function main() {\n    const args = [ 10, 20 ];\n    const result = await execAsync((a, b) =\u003e {\n        return a + b;\n    }, args);\n    console.log(result); // 30\n}\n```\n\n## Example 2\n\n```js\n// import function execAsync(func, args)\n\nfunction testCase() {\n\tlet total = 0;\n\tfor(let i = 0; i \u003c 99999999; ++i) {\n\t\ttotal += Math.random() * 2;\n    }\n\treturn total;\n}\n\nasync function test1() {\n\tconsole.time('single thread');\n\ttestCase();\n\ttestCase();\n\ttestCase();\n\tconsole.timeEnd('single thread');\n}\n\nasync function test2() {\n\tconsole.time('multi thread');\n\tawait Promise.all([\n\t\texecAsync(testCase, []),\n\t\texecAsync(testCase, []),\n\t\texecAsync(testCase, [])\n\t]);\n\tconsole.timeEnd('multi thread');\n}\n```\n\nResults\n\n```\nsingle thread: 3907.119140625ms\nmulti thread: 2017.375732421875ms\n```\n\n## API\n\n```ts\nasync function execAsync\u003cReturnT\u003e(thread: (...args: any[]) =\u003e ReturnT, args: any[]): Promise\u003cReturnT\u003e;\n```\n\n## Limitations\n\nOnly plain type values for arguments.  \nNo access to variables in scope, only arguments.  \nNo native functions or functions defined in other origin.\n\n## Working on\n\n* Callback support\n\n### PS\n\nThere is much complex library - [threads](https://www.npmjs.com/package/threads).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorglod%2Fsimple-multithread-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorglod%2Fsimple-multithread-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorglod%2Fsimple-multithread-js/lists"}