import EventEmitter from "events"; import { Child } from "../Structures/Child.js"; import { RawMessage } from "../Structures/IPCMessage.js"; import { Worker } from "../Structures/Worker.js"; import { ClusterEvents, ClusterKillOptions } from "../types/shared"; import { ClusterManager } from "./ClusterManager"; /** * A self-contained cluster created by the {@link ClusterManager}. Each one has a {@link DjsDiscordClient} that contains * an instance of the bot and its {@link DjsDiscordClient}. When its child process/worker exits for any reason, the cluster will * spawn a new one to replace it as necessary. * @augments EventEmitter */ export declare class Cluster extends EventEmitter { THREAD: typeof Worker | typeof Child; /** * Manager that created the cluster */ manager: ClusterManager; /** * ID of the cluster in the manager */ id: number; /** * Arguments for the shard's process (only when {@link ShardingManager#mode} is `process`) */ args: string[]; /** * Arguments for the shard's process executable (only when {@link ShardingManager#mode} is `process`) */ execArgv: string[]; /** * Internal Shards which will get spawned in the cluster */ shardList: number[]; /** * the amount of real shards */ totalShards: number; /** * Environment variables for the cluster's process, or workerData for the cluster's worker */ env: NodeJS.ProcessEnv & { SHARD_LIST: number[]; TOTAL_SHARDS: number; CLUSTER_MANAGER: boolean; CLUSTER: number; CLUSTER_COUNT: number; DISCORD_TOKEN: string; }; /** * Process of the cluster (if {@link ClusterManager#mode} is `process`) */ thread: null | Worker | Child; restarts: { current: number; max: number; interval: number; reset?: NodeJS.Timeout; resetRestarts: () => void; cleanup: () => void; append: () => void; }; messageHandler: any; /** * Whether the cluster's {@link DjsDiscordClient} is ready */ ready: boolean; /** * @param manager Manager that is creating this cluster * @param id ID of this cluster * @param shardList * @param totalShards */ constructor(manager: ClusterManager, id: number, shardList: number[], totalShards: number); /** * Forks a child process or creates a worker thread for the cluster. * You should not need to call this manually. * @param spawnTimeout The amount in milliseconds to wait until the {@link DjsDiscordClient} has become ready * before resolving. (-1 or Infinity for no wait) */ spawn(spawnTimeout?: number): Promise; /** * Immediately kills the clusters process/worker and does not restart it. * @param options Some Options for managing the Kill * @param options.force Whether the Cluster should be force kill and be ever respawned... */ kill(options: ClusterKillOptions): void; /** * Kills and restarts the cluster's process/worker. * @param options Options for respawning the cluster */ respawn({ delay, timeout }?: import("../types/shared").ClusterManagerSpawnOptions): Promise; /** * Sends a message to the cluster's process/worker. * @param message Message to send to the cluster */ send(message: RawMessage): Promise | undefined; /** * Sends a Request to the ClusterClient and returns the reply * @param message Message, which should be sent as request * @returns Reply of the Message * @example * client.cluster.request({content: 'hello'}) * .then(result => console.log(result)) //hi * .catch(console.error); * @see {@link IPCMessage#reply} */ request(message: RawMessage): Promise; /** * Evaluates a script or function on the cluster, in the context of the {@link DjsDiscordClient}. * @param script JavaScript to run on the cluster * @param context * @param timeout * @returns Result of the script execution */ eval(script: string, context: any, timeout: number): Promise; /** * @param reason If maintenance should be enabled with a given reason or disabled when nonce provided */ triggerMaintenance(reason?: string): Promise | undefined; /** * Handles a message received from the child process/worker. * @param message Message received * @private */ private _handleMessage; /** * Handles the cluster's process/worker exiting. * @private * @param {Number} exitCode */ private _handleExit; /** * Handles the cluster's process/worker error. * @param error the error, which occurred on the worker/child process * @private */ private _handleError; } export interface Cluster { emit: ((event: K, ...args: ClusterEvents[K]) => boolean) & ((event: Exclude, ...args: any[]) => boolean); off: ((event: K, listener: (...args: ClusterEvents[K]) => void) => this) & ((event: Exclude, listener: (...args: any[]) => void) => this); on: ((event: K, listener: (...args: ClusterEvents[K]) => void) => this) & ((event: Exclude, listener: (...args: any[]) => void) => this); once: ((event: K, listener: (...args: ClusterEvents[K]) => void) => this) & ((event: Exclude, listener: (...args: any[]) => void) => this); removeAllListeners: ((event?: K) => this) & ((event?: Exclude) => this); } //# sourceMappingURL=Cluster.d.ts.map