class WorkerPoolService
implements IWorkerPool
Since 0.1.0

The worker pool service registered under CAPABILITIES.WORKER_POOL.

Resolves the worker host once: an injected options.host wins over the runtime's IRuntimeServices.workers. When neither exists (e.g. Cloudflare Workers), the service still constructs — run() throws WorkerPoolUnavailableError, stats() returns [], and shutdown() resolves — so one codebase stays deployable everywhere.

Constructors

WorkerPoolService(
options: WorkerPoolPluginOptions | undefined,
runtime: IRuntimeServices,
collector?: WorkerPoolCollector
)

Methods

run<TInput, TOutput>(
taskModule: string,
input: TInput,
options?: WorkerRunOptions
): Promise<TOutput>

Runs a task on the pool for taskModule, creating it lazily.

shutdown(): Promise<void>

Shuts down every pool (terminating workers, rejecting pending tasks). Safe to call more than once.

stats(): readonly TaskPoolStats[]

Returns a snapshot of every pool created so far.

Usage

import { WorkerPoolService } from "worker-pool-plugin/src/index.ts";