UNPKG

status-sharding

Version:

Welcome to Status Sharding! This package is designed to provide an efficient and flexible solution for sharding Discord bots, allowing you to scale your bot across multiple processes or workers.

37 lines (36 loc) 1.41 kB
import { Worker as WorkerThread, WorkerOptions, MessagePort } from 'worker_threads'; import { Serializable, SerializableInput } from '../types'; export interface WorkerThreadOptions extends WorkerOptions { /** Data to send to the cluster. */ clusterData?: NodeJS.ProcessEnv | undefined; } export declare class Worker { private file; /** The worker process. */ process: WorkerThread | null; /** The options for the worker process. */ workerOptions: WorkerOptions; /** Type-safe listener manager */ private _listeners; /** Creates an instance of Worker. */ constructor(file: string, options: WorkerThreadOptions); /** Spawns the worker. */ spawn(): WorkerThread; /** Respawns the worker. */ respawn(): Promise<WorkerThread>; /** Kills the worker with proper cleanup. */ kill(): Promise<boolean>; /** Clean up worker and listeners */ private _cleanup; /** Sends a message to the worker. */ send<T extends Serializable>(message: SerializableInput<T, true> | unknown): Promise<void>; } /** Worker client class. */ export declare class WorkerClient { /** The IPC port of the worker. */ readonly ipc: MessagePort | null; /** Creates an instance of WorkerClient. */ constructor(); /** Sends a message to the worker. */ send<T extends Serializable>(message: SerializableInput<T, true> | unknown): Promise<void>; }