Skip to content

ClusterWorker

Defined in: packages/sharding/src/worker.ts:29

The worker side of a cluster. It tells the parent when the process is ready, answers the parent’s requests, and asks the parent for IDENTIFY slots. ShardManager uses it automatically inside a cluster; use it directly when you run your own Gateways.

new ClusterWorker(context, endpoint?, options?): ClusterWorker

Defined in: packages/sharding/src/worker.ts:64

ClusterContext

WorkerEndpoint = ...

(code) => void

Replaces process.exit; for tests.

boolean

Exit when the parent’s IPC channel closes. Without a parent nothing coordinates IDENTIFY or fences this process, and its Gateway sessions would keep running beside a replacement. Default: true for the real process, false for an injected endpoint.

ClusterWorker

readonly context: ClusterContext

Defined in: packages/sharding/src/worker.ts:52

get identifyGate(): IdentifyGate | undefined

Defined in: packages/sharding/src/worker.ts:99

The gate to use when the parent coordinates IDENTIFY, otherwise undefined.

IdentifyGate | undefined

close(): void

Defined in: packages/sharding/src/worker.ts:144

Stops listening and rejects pending IDENTIFY requests.

void


onRequest(type, handler): this

Defined in: packages/sharding/src/worker.ts:136

Answers requests of type sent with ClusterManager.requestCluster(). The return value (or thrown error) goes back to the caller.

string

RequestHandler

this


ready(shardIds?): void

Defined in: packages/sharding/src/worker.ts:123

Tells the parent every shard of this process finished its handshake.

readonly number[] = ...

void


reportHealth(report): void

Defined in: packages/sharding/src/worker.ts:128

Pushes a health report to the parent without being asked.

WorkerReport

void


static current(): ClusterWorker | undefined

Defined in: packages/sharding/src/worker.ts:33

The worker of this process, or undefined when it was not forked by a ClusterManager.

ClusterWorker | undefined


static reset(): void

Defined in: packages/sharding/src/worker.ts:47

Forgets the process-wide worker (tests).

void