
Bun Workers
When you need to offload CPU-intensive work or run parallel tasks in Bun without blocking your main thread, this covers both Web Workers and Node.js worker_threads APIs. You get practical patterns like worker pools, parallel mapping, and progress reporting, plus the crucial bits about transferable objects and SharedArrayBuffer for efficient data passing. The worker pool implementation is especially handy if you're processing batches of data. One thing to note: the examples lean heavily on TypeScript, which matches how most people actually use Bun, but you'll need to understand the difference between Web Workers (browser-style) and worker_threads (Node-style) to pick the right one for your use case.
- skills.sh installs
- 333
- GitHub stars
- 248
- last updated
- Aug 21, 2026
Install
$ npx -y skills add secondsky/claude-skills --skill bun-workers --agent claude-codeInstalls into .claude/skills of the current project.
Files
Bun Workers
Bun supports Web Workers and Node.js worker_threads for parallel execution.
Web Workers
Basic Usage
// main.ts
const worker = new Worker(new URL("./worker.ts", import.meta.url));
worker.postMessage({ type: "start", data: [1, 2, 3, 4, 5] });
worker.onmessage = (event) => {
console.log("Result:", event.data);
};
worker.onerror = (error) => {
console.error("Worker error:", error.message);
};
// worker.ts
self.onmessage = (event) => {
const { type, data } = event.data;
if (type === "start") {
const result = data.map((x) => x * 2);
self.postMessage(result);
}
};
Worker with URL
// Import from file path
const worker = new Worker(new URL("./worker.ts", import.meta.url));
// Or with blob URL
const code = `
self.onmessage = (e) => {
self.postMessage(e.data * 2);
};
`;
const blob = new Blob([code], { type: "application/javascript" });
const worker = new Worker(URL.createObjectURL(blob));
Transferable Objects
// main.ts
const buffer = new ArrayBuffer(1024 * 1024); // 1MB
const view = new Uint8Array(buffer);
view.fill(42);
Sponsors
Details
- Repository
- github.com/secondsky/claude-skills
- Categories
- Backend & APIs, Automation & Workflows
- First seen
- Jun 3, 2026
More from secondsky/claude-skills
All 146- Bun Shell331
- Bun React Ssr330
- Bun Tanstack Start329
- Cloudflare Workers Performance329
- Bun Hot Reloading328
- Bun Redis328
- Bun Ffi326
- Bun Jest Migration326
- Bun Websocket Server326
- Cloudflare Workers Runtime Apis326
- Swift Best Practices326
- Bun Nuxt323
- Bun Macros322
- Cloudflare Workers Frameworks321
- Supabase Postgres Best Practices319
- Cloudflare Workers Ci Cd318
- Cloudflare Workers Dev Experience317
- Cloudflare Workers Observability315
- Cloudflare Workers Migration310
- Cloudflare Workers Multi Lang310
- Verification Before Completion310
- Nuxt Studio308
- Neon Vercel Postgres294
- Chrome Devtools288