@suaveplan/queue-distribution-worker-thread - Web-Worker / Node worker_threads transport plugin for @suaveplan/queue-distribution: caller-injected WorkerFactory bridges to the platform-native worker, message correlation, Zod-validated reply envelope, bounded outstanding-request map.
Summary
Web-Worker / Node worker_threads transport plugin for @suaveplan/queue-distribution. Ships WorkerThreadCommunicator (a ThreadWorkerLike-based message bridge with Zod-validated envelopes, bounded outstanding-request map, AbortSignal cancellation, structured timeouts) and WorkerThreadWorker (an AbstractWorker subclass that drives the communicator and reacts to crash / exit events).
The plugin lives separately from the core distribution package so HTTP-only and in-process-only consumers don't carry worker-thread bridge code they never use.
Documentation tree
- worker-thread — (no submodules)
- worker-thread-communicator — (no submodules)
- errors — (no submodules)
- queue-distribution-worker-thread-error — (no submodules)
- observability — (no submodules)
- instruments — (no submodules)
- worker-thread — (no submodules)
- worker-thread-worker — (no submodules)
Install
bun add @suaveplan/queue-distribution-worker-thread
Quick start
import {
WorkerManager,
WorkerPool,
} from "@suaveplan/queue-distribution";
import { WorkerThreadWorker } from "@suaveplan/queue-distribution-worker-thread";
const pool = new WorkerPool();
pool.addWorker(
new WorkerThreadWorker(
() => new Worker(new URL("./worker.ts", import.meta.url), { type: "module" }),
{ id: "hot-1", capacity: 4 },
),
);
await pool.startAllWorkers();
const manager = new WorkerManager(pool, { autoHealthCheck: false });
const result = await manager.assignTask(task, input);
Modules
- Errors —
QueueDistributionWorkerThreadError+ 4 stableWT.*codes. - WorkerThreadCommunicator — message bridge with Zod envelope.
- WorkerThreadWorker —
AbstractWorkersubclass. - Observability — OTel counters, histograms, tracer.
Design highlights
- 100% test coverage (statements + branches + functions + lines).
- Same class runs against browser
Workerand Nodeworker_threadsvia injectableWorkerFactory. - Bounded
Map<requestId, PendingRequest>— never leaks outstanding entries. - Zod-validated envelope in both directions rejects malformed traffic at the boundary.
- Structured
QueueDistributionWorkerThreadErrorsubclasses with a frozen stable-code registry. - AbortSignal threaded through every request; terminate() fails all in-flight requests.
Status
Part of the rebuild — version 0.1.0 while it stabilises.