{"id":19636787,"url":"https://github.com/mizchi/minlink","last_synced_at":"2025-08-24T04:04:10.170Z","repository":{"id":137922933,"uuid":"289839306","full_name":"mizchi/minlink","owner":"mizchi","description":"Minimum(\u003e 1kb) and isomorphic worker wrapper with comlink like rpc.","archived":false,"fork":false,"pushed_at":"2020-08-25T18:00:19.000Z","size":165,"stargazers_count":19,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T08:04:03.305Z","etag":null,"topics":["comlink","minlink","multithreading","nodejs","webworker","worker"],"latest_commit_sha":null,"homepage":"","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/mizchi.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":"2020-08-24T05:47:05.000Z","updated_at":"2024-01-17T15:01:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"43030c63-ea28-4bed-ae94-75223fd00f78","html_url":"https://github.com/mizchi/minlink","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizchi%2Fminlink","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizchi%2Fminlink/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizchi%2Fminlink/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizchi%2Fminlink/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mizchi","download_url":"https://codeload.github.com/mizchi/minlink/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251284876,"owners_count":21564687,"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":["comlink","minlink","multithreading","nodejs","webworker","worker"],"created_at":"2024-11-11T12:31:20.449Z","updated_at":"2025-08-24T04:04:10.158Z","avatar_url":"https://github.com/mizchi.png","language":"TypeScript","readme":"# minlink\n\nMinimum(~ 1kb) and isomorphic worker wrapper with comlink like rpc.\n\n```bash\nnpm install minlink --save\n# or\nyarn add minlink\n```\n\n## Why?\n\n- WebWorker(DedicateWorker) and node's Worker(`threads`) have similar api but not same one. This library wraps them to same rpc.\n- `minlink` is inspired by `comlink` but to keep simple and small core, minlink does not use ES2015 Proxy(or its polyfill). Instead of proxy, `minlink` provides typescript's type utils.\n\n## Requirements\n\n- Node 14+\n- Modern Browser + IE11(WIP: Not tested yet)\n\n## Browser WebWorker\n\nMinlink takes WebWorker as expose/wrap. Bundle them with webpack or rollup.\n\n```ts\n// browser worker.js\nimport { expose } from \"minlink/dist/browser.mjs\";\nconst impl = {\n  async foo(n; number) {\n    return n + 1;\n  },\n};\nexpose(self, impl);\n\n// browesr main.js\n// import { wrap } from \"minlink/dist/browser.legacy.js\"; // for ie11. UMD build.\nimport { wrap } from \"minlink/dist/browser.mjs\";\nconst api = wrap(new Worker(\"./worker.js\"));\nconst ret = await api.exec(\"foo\", 1);\nconsole.log(ret); // =\u003e 2\nawait api.terminate();\n```\n\n## Node Worker\n\nMinlink takes `worker_threads/Worker` as expose/wrap.\n\n```ts\n// main.mjs\nimport { wrap } from \"comlink/dist/node.mjs\";\nimport { Worker } from \"worker_threads\";\nconst worker = new Worker(\"./worker.mjs\");\nconst api = wrap(worker);\nconst res = await api.exec(\"foo\", 1);\nconsole.log(\"response\", res);\n\n// worker.mjs\nimport { expose } from \"minlink/dist/node.mjs\";\nimport { parentPort } from \"worker_threads\";\nexpose(parentPort, {\n  async foo(n) {\n    return n + 1;\n  },\n});\n```\n\n## Advanced: TypeScript utilities\n\n```ts\n// browser/worker.ts\nimport { expose } from \"minlink/dist/browser.mjs\";\nconst impl = {\n  async foo(n; number) {\n    return n + 1;\n  },\n};\nexport type RemoteImpl = typeof impl;\nexpose(self, impl);\n\n// browesr/main.ts\nimport type { RemoteImpl } from \"./worker.ts\"; // Typescript 3.9+ Type only import\nimport { wrap } from \"minlink/dist/browser.mjs\";\nconst api = wrap\u003cRemoteImpl\u003e(new Worker(\"/worker.js\")); // take RemoteImpl as `wrap(...)`'s type argument.\nconst ret = await api.exec(\"foo\", 1); // pass\nconst ret = await api.exec(\"foo\", \"invalid arg\"); // type error\n```\n\n## Advanced: Transferrable\n\n```ts\nconst buf = new Uint8Array([1]);\nconst ret = await api.exec([\"foo\", [buf]], buf); // pass\n```\n\n## Advanced: Call client expose from worker.\n\nTBD\n\n## Inspired by ...\n\n- https://github.com/GoogleChromeLabs/comlink\n- https://github.com/developit/web-worker\n\n## ChangeLog\n\n- v2: transferrable uses `['foo', [buf]]` from `{cmd: 'foo', transferrable: [buf]}`\n- v1: release\n\n## LICENSE\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmizchi%2Fminlink","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmizchi%2Fminlink","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmizchi%2Fminlink/lists"}