← The API

Phaser AE

API docs

v3.0.0-1187 exports in 24 modulesreleased October 14, 2026

ContentsWorkers

Need to get started? Install the Phaser AE CLI →

Tools

Workers

The worker pool and its job protocol

engine/kernel/src/workers.ts

Types

JobSpec

interface JobSpec<In, Out>

From @phaser-ae/kernel

One job to run on a worker thread.

  • readonly kind: string — <packId>/<jobName> — resolved to the pack's bundled worker module.
  • readonly input: In — The job's input, structured-cloned to the worker.
  • readonly transfer?: ReadonlyArray<Transferable> — Buffers to move rather than copy; they are unusable on this side afterwards.
  • readonly signal?: AbortSignal — Cancels queued or running work; the promise rejects. Cancelling a running job terminates its worker.
  • readonly __out?: Out — Type carrier only, never set: the result type Out.

WorkerLike

interface WorkerLike

From @phaser-ae/kernel

The transport a pool thread needs: a module Worker in a browser, or a stand-in a test supplies through create.

  • onmessage: ((event: MessageEvent<unknown>) => void) | null — Response messages from the module worker.
  • onerror: ((event: ErrorEvent) => void) | null — Fatal worker errors; the pool fails the running job and retires the thread.
  • postMessage(message: unknown, transfer: Transferable[]): void — Send a structured-cloned job and transfer ownership of listed buffers.
  • terminate(): void — Immediately stop this thread.

WorkerPool

interface WorkerPool

From @phaser-ae/kernel

The pool. Threads are made lazily, one job kind per thread, up to size; an idle thread of another kind is retired to make room. Results settle in submission order at frame boundaries, so a later job never overtakes an earlier one.

  • run<In, Out>(job: JobSpec<In, Out>): Promise<Out> — Run a job. Resolves with the worker's result at a frame boundary, so results merge deterministically; the game must be running for it to settle. Rejects for an unknown kind, a full queue, an abort, a worker error, or a destroyed pool.
  • has(kind: string): boolean — Does the pool have an entry for this job kind (is its pack composed with that job)?
  • readonly size: number — Threads alive now.
  • readonly queued: number — Jobs waiting for a thread.

WorkerPoolOptions

interface WorkerPoolOptions

From @phaser-ae/kernel

The pool's configuration, from the bake; game code calls the composed pack's async API instead.

  • entries?: Readonly<Record<string, string | URL>> — Composed job kinds mapped to their bundled module URLs.
  • size?: number — Most threads at once. Default 2.
  • maxQueued?: number — Most jobs waiting for a thread, beyond those running. Default 64; one more is rejected.
  • create?: (url: string | URL) => WorkerLike — Make a thread for a module URL. Default: new Worker(url, { type: 'module' }).