WorkerPool
Defined in: src/modules/worker-pool/worker-pool.ts:47
A fixed pool of Web Workers that runs jobs off the main thread. Pass a spawn
function (typically () => new Worker(new URL('./job.worker.ts', import.meta.url), { type: 'module' })); each run returns a Promise
that resolves with the worker’s result. Jobs queue when every worker is busy
and dispatch as workers free up. The worker script wires the message protocol
via handleJobs.
This is task parallelism (offload a whole job), distinct from data parallelism over shared memory — see docs/decisions.md, “Task parallelism and data parallelism are separate tools”.
Type Parameters
Section titled “Type Parameters”TIn
TOut
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new WorkerPool<
TIn,TOut>(spawn,options?):WorkerPool<TIn,TOut>
Defined in: src/modules/worker-pool/worker-pool.ts:54
Parameters
Section titled “Parameters”() => WorkerLike
options?
Section titled “options?”WorkerPoolOptions = {}
Returns
Section titled “Returns”WorkerPool<TIn, TOut>
Methods
Section titled “Methods”dispose()
Section titled “dispose()”dispose():
void
Defined in: src/modules/worker-pool/worker-pool.ts:72
Terminate every worker and drop any queued jobs.
Returns
Section titled “Returns”void
run(
input):Promise<TOut>
Defined in: src/modules/worker-pool/worker-pool.ts:98
Run one job. Resolves with the worker’s result, or rejects if it threw.
Parameters
Section titled “Parameters”TIn
Returns
Section titled “Returns”Promise<TOut>