# Variable: worker (/pixi-vn/index/namespaces/Game/variables/worker)



\> `const` **worker**: `object`

Defined in: [src/index.ts:529](https://github.com/DRincs-Productions/pixi-vn/blob/5bb5bb1f92e38998ea2f477b600168d8da3ece19/src/index.ts#L529)

Optional integration point for offloading Pixi'VN's own heavy, pure computations (state
diffing/restoring/cloning for `stepHistory.back()`/`add()`/`export()`) to a Worker the game
project provides. Pixi'VN never creates a Worker itself, decides on its own which eligible
work actually goes through it, and falls back to computing the same thing synchronously
on the main thread whenever none is registered - so projects that can't or don't want to
use Workers (SSR, certain embeds, ...) are unaffected either way.

The game project stays in control of the actual `new Worker(...)` call (bundler-specific
URL/`type: "module"` handling, CSP, lifecycle) and only needs to point that worker's
message handling at `handleGameWorkerMessage` from `@drincs/pixi-vn/worker`:

```ts
// main thread
import { Game } from "@drincs/pixi-vn";
const worker = new Worker(new URL("./game-worker.ts", import.meta.url), { type: "module" });
Game.worker.register(worker);

// game-worker.ts
import { handleGameWorkerMessage } from "@drincs/pixi-vn/worker";
self.onmessage = async (event) => {
    const response = await handleGameWorkerMessage(event.data);
    if (response) self.postMessage(response);
};
```

A third-party library built on top of Pixi'VN (one with `@drincs/pixi-vn` as a peer
dependency) can share this same worker for its own heavy, pure computations instead of
needing one of its own - see `registerGameWorkerHandler` (worker side) and
`GameWorkerManager.custom` (main-thread side), both from `@drincs/pixi-vn/worker`.

## Type Declaration [#type-declaration]

### register [#register]

\> **register**: (`worker`) => `void`

#### Parameters [#parameters]

##### worker [#worker]

`Worker`

#### Returns [#returns]

`void`

### unregister [#unregister]

\> **unregister**: () => `void`

#### Returns [#returns-1]

`void`

### isAvailable [#isavailable]

#### Get Signature [#get-signature]

\> **get** **isAvailable**(): `boolean`

##### Returns [#returns-2]

`boolean`
