{"id":30589263,"url":"https://github.com/xan105/web-worker-thread","last_synced_at":"2026-02-11T06:32:20.436Z","repository":{"id":311256182,"uuid":"1043106777","full_name":"xan105/web-worker-thread","owner":"xan105","description":"Execute Web Workers as promise without dedicated script file","archived":false,"fork":false,"pushed_at":"2025-08-23T06:49:12.000Z","size":46,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-01T06:25:24.818Z","etag":null,"topics":["blob","browser","coroutine","thread","web-workers"],"latest_commit_sha":null,"homepage":"","language":"HTML","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/xan105.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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,"zenodo":null},"funding":{"github":"xan105","custom":"https://www.paypal.me/xan105"}},"created_at":"2025-08-23T06:39:07.000Z","updated_at":"2025-08-23T06:49:14.000Z","dependencies_parsed_at":"2025-08-23T11:22:14.425Z","dependency_job_id":"9ad0d88e-1e87-4a33-b2b0-943eaa478fec","html_url":"https://github.com/xan105/web-worker-thread","commit_stats":null,"previous_names":["xan105/web-worker-thread"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/xan105/web-worker-thread","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xan105%2Fweb-worker-thread","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xan105%2Fweb-worker-thread/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xan105%2Fweb-worker-thread/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xan105%2Fweb-worker-thread/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xan105","download_url":"https://codeload.github.com/xan105/web-worker-thread/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xan105%2Fweb-worker-thread/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29328261,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T06:13:03.264Z","status":"ssl_error","status_checked_at":"2026-02-11T06:12:55.843Z","response_time":97,"last_error":"SSL_read: 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":["blob","browser","coroutine","thread","web-workers"],"created_at":"2025-08-29T15:38:23.570Z","updated_at":"2026-02-11T06:32:20.431Z","avatar_url":"https://github.com/xan105.png","language":"HTML","funding_links":["https://github.com/sponsors/xan105","https://www.paypal.me/xan105"],"categories":[],"sub_categories":[],"readme":"About\n=====\n\nExecute Web Workers as promise without dedicated script file.\n\n📦 Scoped `@xan105` packages are for my own personal use but feel free to use them.\n\nExample\n=======\n\n```js\nimport { threadify } from \"@xan105/web-worker-thread\";\n\nfunction fibonacci(n) {\n  if (n \u003c= 1n) return n;\n  let a = 0n, b = 1n;\n  for (let i = 2n; i \u003c= n; i = i + 1n) {\n    [a, b] = [b, a + b];\n  }\n  return b;\n}\n\nconst n = await threadify(fibonacci)(100000n);\nconsole.log(n);\n```\n\nThis can be used as a _\"coroutine-like\"_ with an AbortController:\n\n```js\nimport { threadify } from \"@xan105/web-worker-thread\";\n\nfunction timer(i){\n  return new Promise((resolve) =\u003e setTimeout(() =\u003e resolve(), i));\n}\n\nconst controller = new AbortController();\nconst { signal } = controller;\nthreadify(timer, { signal })(500).catch(console.error);\nsetTimeout(() =\u003e controller.abort(), 100);\n```\n\nInstall\n=======\n\n```\nnpm i @xan105/web-worker-thread\n```\n\n💡 The bundled library and its minified version can be found in the `./dist` folder.\n\n### Via importmap\n\nCreate an importmap and add it to your html:\n\n```html\n  \u003cscript type=\"importmap\"\u003e\n  {\n    \"imports\": {\n      \"@xan105/web-worker-thread\": \"./path/to/node_modules/@xan105/web-worker-thread/dist/thread.min.js\"\n    }\n  }\n  \u003c/script\u003e\n  \u003cscript src=\"./index.js\" type=\"module\"\u003e\u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nindex.js:\n\n```js\n  import { threadify } from \"@xan105/web-worker-thread\"\n  await threadify(foo)(\"bar\");\n```\n\nAPI\n===\n\n⚠️ This module is only available as an ECMAScript module (ESM) and is intended for the browser.\n\n## Named export\n\n### `threadify(fn: function | Promise, option?: object): (...args: unknown[]) =\u003e Promise\u003cunknown\u003e`\n\nSpawn a web worker and run the given function (sync or async) inside the web worker.\n\nℹ️ Usage is similar to `node:util/promisify` syntax:\n\n```js\nimport { threadify } from \"@xan105/web-worker-thread\";\n\nfunction double(i){\n  return i * 2;\n}\n\nconst i = await threadify(double)(2);\nconsole.log(i); //4\n```\n\n**⚙️ Options**\n\n```ts\n{\n  timeout?: number,\n  importScripts?: string[],\n  signal?: AbortSignal\n}\n```\n\n- `timeout?: number` (0)\n\nOptional timeout (in ms) to cancel the web worker if it takes too much time.\n\n- `importScripts?: string[]` (none)\n\nOptional array of script path(s) to import into the web worker's scope.\u003cbr/\u003e\nSee [importScripts](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts) for more details.\n\n- `signal?: AbortSignal` (none)\n\nOptional Abort controller signal to abort the web worker.\u003cbr/\u003e\nSee [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) for more details.\n\n**↩️ Return**\n\nReturns a **function** that, when called with any arguments, executes the original function in a **separate thread** (web worker) and returns a **Promise** that: \n\n- ✔️ resolves to the original function's result\n- ❌ or rejects on error","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxan105%2Fweb-worker-thread","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxan105%2Fweb-worker-thread","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxan105%2Fweb-worker-thread/lists"}