import { ClusterEvents, ClusterKillOptions, EvalOptions, Serialized, Awaitable, ValidIfSerializable, SerializableInput, Serializable } from '../types'; import { BaseMessage, DataType } from '../other/message'; import { Worker as WorkerThread } from 'worker_threads'; import { RefClusterManager } from './clusterManager'; import { ClientRefType } from './clusterClient'; import { ChildProcess } from 'child_process'; import { Worker } from '../classes/worker'; import { Child } from '../classes/child'; import { Guild } from 'discord.js'; import EventEmitter from 'events'; /** A self-contained cluster created by the ClusterManager. */ export declare class Cluster extends EventEmitter { manager: InternalManager; id: number; shardList: number[]; /** Represents whether the cluster is ready. */ ready: boolean; /** Exited. */ exited: boolean; /** Indicates that this cluster is currently in a respawn flow. */ respawning: boolean; /** Represents the child process/worker of the cluster. */ thread: null | Worker | Child; /** Represents the last time the cluster received a heartbeat. */ lastHeartbeatReceived?: number; /** Message processor that handles messages from the child process/worker/manager. */ private messageHandler?; /** Represents the environment data of the cluster. */ private envData; /** Creates an instance of Cluster. */ constructor(manager: InternalManager, id: number, shardList: number[]); /** Count of shards assigned to this cluster. */ get totalShards(): number; /** Count of clusters managed by the manager. */ get totalClusters(): number; /** Spawn function that spawns the cluster's child process/worker with proper event management. */ spawn(spawnTimeout?: number): Promise; private _setupEventListeners; kill(options?: ClusterKillOptions): Promise; /** Respawn function that respawns the cluster's child process/worker. */ respawn(delay?: number, timeout?: number): Promise; /** Send function that sends a message to the cluster's child process/worker. */ send(message: SerializableInput): Promise; /** Request function that sends a message to the cluster's child process/worker and waits for a response. */ request(message: SerializableInput, options?: { timeout?: number; }): Promise>; /** Broadcast function that sends a message to all clusters. */ broadcast(message: SerializableInput, sendSelf?: boolean): Promise; /** Eval function that evaluates a script on the current cluster. */ eval>(script: string | ((cluster: C, context: Serialized

) => Awaitable), options?: Exclude, 'cluster'>): Promise>; /** EvalOnClient function that evaluates a script on a specific cluster. */ evalOnClient(script: string | ((client: C, context: Serialized

) => Awaitable), options?: EvalOptions

): Promise>; /** EvalOnCluster function that evaluates a script on a specific cluster. */ evalOnGuild(guildId: string, script: string | ((client: C, context: Serialized

, guild: Guild | undefined) => Awaitable), options?: EvalOptions

): Promise>; /** Function that allows you to construct your own BaseMessage and send it to the cluster. */ _sendInstance(message: BaseMessage): Promise; /** Message handler function that handles messages from the cluster's child process/worker/manager. */ private _handleMessage; /** Exit handler function that handles the cluster's child process/worker exiting. */ private _handleExit; /** Error handler function that handles errors from the cluster's child process/worker/manager. */ private _handleError; /** Handle unexpected disconnection. */ private _handleDisconnect; /** Handle unexpected exit/crash. */ private _handleUnexpectedExit; } export type RefCluster = Cluster; export declare interface Cluster { /** Emit an event. */ emit: ((event: K, ...args: ClusterEvents[K]) => boolean) & ((event: Exclude, ...args: unknown[]) => boolean); /** Remove an event listener. */ off: ((event: K, listener: (...args: ClusterEvents[K]) => void) => this) & ((event: Exclude, listener: (...args: unknown[]) => void) => this); /** Listen for an event. */ on: ((event: K, listener: (...args: ClusterEvents[K]) => void) => this) & ((event: Exclude, listener: (...args: unknown[]) => void) => this); /** Listen for an event once. */ once: ((event: K, listener: (...args: ClusterEvents[K]) => void) => this) & ((event: Exclude, listener: (...args: unknown[]) => void) => this); /** Remove all listeners for an event. */ removeAllListeners: ((event?: K) => this) & ((event?: Exclude) => this); }