Skip to content

WorkerClient

Signature

@Mixins(RegisteredPluginExtension)export declare class WorkerClient<Ready extends boolean = boolean> extends BaseClient

Properties

promises: Map<string, {    resolve: (value: any) => void;    timeout: NodeJS.Timeout;}>;
private dispatchState;

Whether gateway events reach handlers. A hot reload replacement waits on standby, only building its cache, until the manager switches to it; the worker it replaces then stops and drains.

private standbyReadiness;

The readiness handlers skipped on standby, in startup order, replayed when the replacement takes over.

private inFlightWork;

Dispatched work a worker replaced by a hot reload waits for before it closes its sessions.

get hotReloadState(): 'active' | 'standby' | 'stopped';

Where this worker stands in a hot reload: `'active'` handles gateway events, `'standby'` is a replacement still preparing next to the worker it replaces, and `'stopped'` was replaced and is draining. Outside a hot reload it is always `'active'`.

get isHotReloadReplacement(): boolean;

Whether `WorkerManager.hotReload` started this worker as a replacement for another one.

private runHotReloadHook;

Runs one of the app's hot reload hooks. A hook that throws is logged instead of breaking the reload. Once a hook starts, it can outlive `timeoutMs` while the reload moves on.

private replayStandbyReadiness;

Runs the readiness handlers skipped on standby, in startup order.

private handleShardPayload;

Tracks the complete shard callback, including the user hook, for hot reload draining.

private handleInactivePacket;

A replacement on standby only builds its cache and reports readiness. A stopped worker keeps its own cache current too, so it can take events back if its replacement fails to take over.

botIdSetter
set botId(id: string);
botIdGetter
get botId(): string;

Methods

requestHotReload(options?: WorkerHotReloadRequestOptions & {    onProgress?(event: HotReloadProgress): void;}): Promise<HotReloadResult>;

Asks the `WorkerManager` to hot reload workers, possibly including this one. See `WorkerManager.hotReload` for how the reload works and what it guarantees. `onProgress` receives each stage as the manager reports it. If this worker is replaced, the promise resolves with the entries so far, including this worker's own, before it is told to drain, so it can still reply or log. Its stop and drain still follow. A plain `Client` has no manager; hot reload needs the `WorkerManager`.

sendGatewayPayload<T extends GatewaySendPayload>(shardId: number, payload: T): Promise<boolean>;

Sends a Gateway payload through the worker client's plugin wrappers and shard rate limiter.

Returns

`false` when a plugin wrapper vetoes the payload, otherwise `true` after it is sent.

tellWorker<R, V extends Record<string, unknown>>(workerId: number, func: (_: this, vars: V) => R, vars: V): Promise<R>;
tellWorkers<R, V extends Record<string, unknown>>(func: (_: this, vars: V) => R, vars: V): Promise<Awaited<R>[]>;
close(): Promise<void>;

Closes resources managed by the plugin lifecycle. This waits for in-flight plugin setup and runs `SeyfertPlugin.teardown`. It does not close the gateway, REST client, or cache adapter.

uploadCommands({ applicationId, cachePath }?: {    applicationId?: string;    cachePath?: string;}): Promise<void>;