{"id":13847242,"url":"https://github.com/lukeschaefer/WorkerBee","last_synced_at":"2025-07-12T08:31:28.316Z","repository":{"id":57127208,"uuid":"42746826","full_name":"lukeschaefer/WorkerBee","owner":"lukeschaefer","description":"Inline Web Workers without external files","archived":false,"fork":false,"pushed_at":"2022-02-15T21:55:19.000Z","size":97,"stargazers_count":34,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-11T10:19:34.391Z","etag":null,"topics":["javascript","typescript","worker"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/lukeschaefer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-18T21:00:43.000Z","updated_at":"2025-06-06T14:44:13.000Z","dependencies_parsed_at":"2022-08-31T17:20:51.032Z","dependency_job_id":null,"html_url":"https://github.com/lukeschaefer/WorkerBee","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lukeschaefer/WorkerBee","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeschaefer%2FWorkerBee","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeschaefer%2FWorkerBee/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeschaefer%2FWorkerBee/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeschaefer%2FWorkerBee/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukeschaefer","download_url":"https://codeload.github.com/lukeschaefer/WorkerBee/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeschaefer%2FWorkerBee/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259332295,"owners_count":22842037,"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":["javascript","typescript","worker"],"created_at":"2024-08-04T18:01:14.293Z","updated_at":"2025-07-12T08:31:27.783Z","avatar_url":"https://github.com/lukeschaefer.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# WorkerBee\n\nWorkerBee is a minimal TypeScript library to make using Web Workers as easy as possible. \nInstead of having to create a seperate file for code that is run in a different thread, \nworkers can be made inline with their own functions and be communicated with asynchronously.\n\n## Why?\n\nJavascript is single-threaded. If a complex operation is running for a while, nothing else will\nrun, and your browser will slow down, and your UI will become unresponsive. \n\nHere's a quick example of a function that can run for a long time if you're not careful:\n\n```typescript\n// From https://stackoverflow.com/a/57012040:\nconst findNthPrime = (n : number) =\u003e {\n  const primes = [];\n  let i = 1;\n  while (i++ \u0026\u0026 primes.length \u003c n) {\n    primes.reduce((a,c)=\u003e(i%c)*a,2) \u0026\u0026 prime.push(i);\n  }\n  return primes.pop();\n}\n\n// Will likely cause your browser to become unresponsive:\nconst result = findNthPrime(100000);\n```\n\nWith WorkerBee - if you have a simple, self-contained function like that, you can execute\nit another thread like so:\n\n```typescript\nconst workerFindNthPrime = miniWorker(findNthPrime);\nconst result = await workerFindNthPrime(100000);\n```\n\nAnd things will work nice and smoothly, no matter how long that operation takes.\nSee below for more complex use-cases.\n\n## Installation\n\n```\nnpm install @lukeschaefer/worker-bee\n```\n    \n## Usage:\n\nThere are two ways of creating workers in WorkerBee:\n\n### `miniWorker()`\n\nLike we saw above, simply give miniWorker a self-contained function, and it can execute it in a separate thread:\n\n```typescript\nimport { miniWorker } from '@lukeschaefer/worker-bee';\n\nconst multiplier = miniWorker((x, y) =\u003e {\n  return x * y;\n});\n\nconst result = await multiplier(12,3);\nconsole.log(result); // 36 is logged\n```\n\nBut that's about all it can do.\n\n### `createWorker`\n\n`createWorker` takes in an initialization object, which can consist of properties and methods to call. \nIt will generate accessors and setters so that you can interact with your Web Worker as easily as a normal object:\n\n```typescript\n\nconst usefulWorker = createWorker({\n  counter: 0,\n  addToCounter: function(input: number) {\n    this.counter += input;\n    return this.counter;\n  },\n  addRandomToCounter: function() {\n    return this.addToCounter(Math.random());\n  }\n});\n\nusefulWorker.counter = 20;\n\nusefulWorker.addToCounter(10); // Promise\u003c30\u003e\nusefulWorker.addRandomToCounter(); // Promise\u003c30.123\u003e\n```\n\n`createWorker` workers come with a few helper functions as well:\n\n  - `destroy()` - Closes the webworker.\n  - `importScript()` - Makes the webworker call `loadScript`\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeschaefer%2FWorkerBee","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukeschaefer%2FWorkerBee","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeschaefer%2FWorkerBee/lists"}