# WorkerQueue

Class

Source: https://github.com/playcanvas/splat-transform/blob/b6424a5b3b929695fbaafe738a995adb1240d675/src/lib/workers/worker-queue.ts#L301

A small cross-platform (Node + browser) worker pool running the CPU-heavy
tasks defined in tasks.ts off the main thread. The worker entry is built and
shipped as `dist/worker.mjs`; the pool spawns it from a URL resolved
relative to the library bundle. Node and bundlers that rewrite
`new Worker(new URL('./worker.mjs', import.meta.url))` (e.g. Vite, webpack)
pick it up automatically; with other bundlers, set `WorkerQueue.workerUrl`
to the deployed worker asset (mirroring `WebPCodec.wasmUrl`).

Workers spawn lazily on demand and run one task at a time. When workers are
unavailable (running from source via tsx, `maxWorkers = 0`, or spawn fails)
every task runs inline on the calling thread instead - same code, same
results, just serial.

## Accessors

### maxWorkers

```ts
static get maxWorkers(): number
static set maxWorkers(value: number)
```

Maximum number of worker threads. Defaults to one less than the
available hardware concurrency, capped at 4. (Peak memory scales with
worker count, since each holds its own WebP WASM heap; 4 captures most
of the parallelism for SOG writes.)

### workerUrl

```ts
static get workerUrl(): string
static set workerUrl(value: string)
```

URL of the worker script, or null when auto-resolved relative to the
bundle.

## Methods

### destroy

```ts
static destroy(): Promise<void>
```

Waits for in-flight tasks to settle, then terminates all workers.
Optional: idle workers don't keep the Node process alive, and workers
respawn lazily on the next run() call.

**Returns** `Promise<void>`: A promise that resolves once all workers are terminated.
