Documentation / @zerotal/queue / index / WorkerPool
Class: WorkerPool
Defined in: queue/src/WorkerPool.ts:54
Manages a pool of Bun Web Worker threads for off-main-thread job execution.
Each worker is a genuine OS thread (not just a separate V8 context), so CPU-intensive jobs run without stalling the HTTP event loop.
Usage: const pool = new WorkerPool({ size: 2, bootstrapPath: '...' }); await pool.start(); // spawns + bootstraps threads const result = await pool.run(record); // executes job on a free thread await pool.terminate(); // cleanly shuts threads down
Constructors
Constructor
new WorkerPool(
opts):WorkerPool
Defined in: queue/src/WorkerPool.ts:58
Parameters
opts
Returns
WorkerPool
Methods
start()
start():
Promise<void>
Defined in: queue/src/WorkerPool.ts:64
Spawn all worker threads and wait until every thread has bootstrapped.
Returns
Promise<void>
run()
run(
record):Promise<WorkerResult>
Defined in: queue/src/WorkerPool.ts:189
Send a job record to a free worker thread.
When every thread is busy the job waits in memory, up to WorkerPoolOptions.maxPending. Beyond that it is reported as failed straight away: a waiting job is already claimed from the driver, and one that waits past its visibility timeout gets reclaimed and run a second time while the first copy is still queued here.
Parameters
record
Returns
Promise<WorkerResult>
terminate()
terminate():
Promise<void>
Defined in: queue/src/WorkerPool.ts:210
Terminate all worker threads. Call after QueueManager.drain() completes.
Returns
Promise<void>