Options
All
  • Public
  • Public/Protected
  • All
Menu

Handles communication between clusters, services, and the admiral.

Hierarchy

  • EventEmitter
    • IPC

Index

Properties

centralStore: CentralStore
events: Map<string | number, ((msg: any) => void)[]>
fetchTimeout: number
ipcEventListeners: Map<string | number, ((msg: any) => void)[]>
messageHandler?: (message: any) => void

Type declaration

    • (message: any): void
    • Parameters

      • message: any

      Returns void

captureRejectionSymbol: typeof captureRejectionSymbol
captureRejections: boolean

Sets or gets the default captureRejection value for all emitters.

defaultMaxListeners: number
errorMonitor: typeof errorMonitor

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

Methods

  • addListener(event: string | symbol, listener: (...args: any[]) => void): IPC
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns IPC

  • admiralBroadcast(op: string, message?: unknown): void
  • allClustersCommand(message?: unknown, receptive?: boolean, returnTimeout?: number, callback?: (clusterID: number, data?: any) => void): void | Promise<Map<number, any>>
  • Execute a cluster command on all clusters

    example
    this.ipc.allClustersCommand("hello clusters!", true, undefined, (id, data) => {
    console.log(`I just received ${data} from ${id}!`);
    })
    .then((data) => this.ipc.log(`All my clusters responded and my data in a map. Here is the data from cluster 0: ${data.get(0)}`))
    .catch((error) => this.ipc.error(error));

    Parameters

    • Optional message: unknown

      Whatever message you want to send with the command (defaults to null)

    • Optional receptive: boolean

      Whether you expect something to be returned to you from the command (defaults to false)

    • Optional returnTimeout: number

      How long to wait for a return (defaults to options.fetchTimeout)

    • Optional callback: (clusterID: number, data?: any) => void

      Function which will be run everytime a new command return is received

        • (clusterID: number, data?: any): void
        • Parameters

          • clusterID: number
          • Optional data: any

          Returns void

    Returns void | Promise<Map<number, any>>

    Promise which provides a map with the data replied mapped by cluster ID if receptive = true

  • allClustersEval(stringToEvaluate: string, receptive?: boolean, returnTimeout?: number, callback?: (clusterID: number, data?: any) => void): void | Promise<Map<number, any>>
  • Sends an eval to all clusters. The eval occurs from a function within the BaseClusterWorker class. NOTE: Use evals sparingly as they are a major security risk

    example
    this.ipc.allClustersCommand("return 'heyo!'", true, undefined, (id, data) => {
    console.log(`I just received ${data} from ${id}!`);
    })
    .then((data) => this.ipc.log(`All my clusters responded and my data in a map. Here is the data from cluster 0: ${data.get(0)}`))
    .catch((error) => this.ipc.error(error));

    Parameters

    • stringToEvaluate: string

      String to send to eval

    • Optional receptive: boolean

      Whether you expect something to be returned to you from the command (defaults to false)

    • Optional returnTimeout: number

      How long to wait for a return (defaults to options.fetchTimeout)

    • Optional callback: (clusterID: number, data?: any) => void

      Function which will be run everytime a new command return is received

        • (clusterID: number, data?: any): void
        • Parameters

          • clusterID: number
          • Optional data: any

          Returns void

    Returns void | Promise<Map<number, any>>

    Promise which provides a map with the data replied mapped by cluster ID if receptive = true

  • broadcast(op: string, message?: unknown): void
  • Broadcast an event to all clusters and services. The event can be listened to with register

    example
    this.ipc.broadcast("hello clusters!", "Want to chat?");
    

    Parameters

    • op: string

      Name of the event

    • Optional message: unknown

      Message to send

    Returns void

  • clusterCommand(clusterID: string, message?: unknown, receptive?: boolean, returnTimeout?: number): void | Promise<any>
  • Execute a cluster command

    example
    this.ipc.clusterCommand(1, "hello cluster!", true)
    .then((message) => console.log(message))
    .catch((error) => this.ipc.error(error));

    Parameters

    • clusterID: string

      ID of the cluster

    • Optional message: unknown

      Whatever message you want to send with the command (defaults to null)

    • Optional receptive: boolean

      Whether you expect something to be returned to you from the command (defaults to false)

    • Optional returnTimeout: number

      How long to wait for a return (defaults to options.fetchTimeout)

    Returns void | Promise<any>

    Promise with data if receptive = true

  • clusterEval(clusterID: number, stringToEvaluate: string, receptive?: boolean, returnTimeout?: number): void | Promise<any>
  • Sends an eval to the mentioned cluster. The eval occurs from a function within the BaseClusterWorker class. NOTE: Use evals sparingly as they are a major security risk

    example
    this.ipc.clusterEval(1, "return 'hey!'", true)
    .then((data) => this.ipc.log(data))
    .catch((error) => this.ipc.error(error));

    Parameters

    • clusterID: number

      ID of the cluster

    • stringToEvaluate: string

      String to send to eval

    • Optional receptive: boolean

      Whether you expect something to be returned to you from the command (defaults to false)

    • Optional returnTimeout: number

      How long to wait for a return (defaults to options.fetchTimeout)

    Returns void | Promise<any>

    Promise with result if receptive = true

  • collectStats(): Promise<Stats>
  • command(service: string, message?: unknown, receptive?: boolean, returnTimeout?: number): void | Promise<any>
  • deprecated

    Use IPC.serviceCommand

    Parameters

    • service: string
    • Optional message: unknown
    • Optional receptive: boolean
    • Optional returnTimeout: number

    Returns void | Promise<any>

  • createService(serviceName: string, servicePath: string): Promise<undefined | ServiceCollection>
  • Create a service

    example
    const path = require("path");
    this.ipc.createService("myService", path.join(__dirname, "./service.js"))

    Parameters

    • serviceName: string

      Unique ame of the service

    • servicePath: string

      Absolute path to the service file

    Returns Promise<undefined | ServiceCollection>

    Promise which resolves with the service object when it is ready

  • debug(message: unknown, source?: string): void
  • Sends a debug log to the Admiral

    example
    this.ipc.debug("I'm here!");
    

    Parameters

    • message: unknown

      Item to log

    • Optional source: string

      Custom error source

    Returns void

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

  • error(message: unknown, source?: string): void
  • Sends an error log to the Admiral

    example
    this.ipc.error(new Error("big yikes"));
    

    Parameters

    • message: unknown

      Item to log

    • Optional source: string

      Custom error source

    Returns void

  • eventNames(): (string | symbol)[]
  • Returns (string | symbol)[]

  • fetchChannel(id: string): Promise<any>
  • Fetch a cached channel from the Eris client on any cluster

    example
    await this.ipc.fetchChannel('123456789');
    

    Parameters

    • id: string

      Channel ID

    Returns Promise<any>

    The Eris channel object converted to JSON

  • fetchGuild(id: string): Promise<any>
  • Fetch a cached guild from the Eris client on any cluster

    example
    await this.ipc.fetchGuild('123456789');
    

    Parameters

    • id: string

      Guild ID

    Returns Promise<any>

    The Eris guild object converted to JSON

  • fetchMember(guildID: string, memberID: string): Promise<any>
  • Fetch a cached member from the Eris client on any cluster

    example
    await this.ipc.fetchMember('123456789', '987654321');
    

    Parameters

    • guildID: string

      Guild ID

    • memberID: string

      the member's user ID

    Returns Promise<any>

    The Eris member object converted to JSON

  • fetchUser(id: string): Promise<any>
  • Fetch a cached user from the Eris client on any cluster

    example
    await this.ipc.fetchUser('123456789');
    

    Parameters

    • id: string

      User ID

    Returns Promise<any>

    The Eris user object converted to JSON

  • getMaxListeners(): number
  • Returns number

  • getStats(): Promise<Stats>
  • info(message: unknown, source?: string): void
  • Sends an info log to the Admiral

    example
    this.ipc.info("You might want to take a look at this");
    

    Parameters

    • message: unknown

      Item to log

    • Optional source: string

      Custom error source

    Returns void

  • listenerCount(event: string | symbol): number
  • Parameters

    • event: string | symbol

    Returns number

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

  • log(message: unknown, source?: string): void
  • Sends a log to the Admiral

    example
    this.ipc.log("You have reached this line of code");
    

    Parameters

    • message: unknown

      Item to log

    • Optional source: string

      Custom error source

    Returns void

  • off(event: string | symbol, listener: (...args: any[]) => void): IPC
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns IPC

  • on(event: string | symbol, listener: (...args: any[]) => void): IPC
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns IPC

  • once(event: string | symbol, listener: (...args: any[]) => void): IPC
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns IPC

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): IPC
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns IPC

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): IPC
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns IPC

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

  • register(event: string, callback: (msg: any) => void): void
  • Register for an event. This will receive broadcasts and messages sent to this cluster. This will also receive Admiral events if broadcastAdmiralEvents is enabled in options. Events can be sent using sendTo and broadcast

    example
    this.ipc.register("hello!", (message) => {
    // Do stuff
    console.log(message);
    });

    Parameters

    • event: string

      Name of the event

    • callback: (msg: any) => void

      Function run when event is received

        • (msg: any): void
        • Parameters

          • msg: any

          Returns void

    Returns void

  • removeAllListeners(event?: string | symbol): IPC
  • Parameters

    • Optional event: string | symbol

    Returns IPC

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): IPC
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns IPC

  • Reshards all clusters

    Parameters

    Returns Promise<void>

    Promise which resolves when resharding is complete (note that this only resolves when using a service or the Admiral)

  • restartAllClusters(hard?: boolean): void
  • Restarts all clusters

    Parameters

    • Optional hard: boolean

      Whether to ignore the soft shutdown function

    Returns void

  • restartAllServices(hard?: boolean): void
  • Restarts all services

    Parameters

    • Optional hard: boolean

      Whether to ignore the soft shutdown function

    Returns void

  • restartCluster(clusterID: number, hard?: boolean): Promise<undefined | ClusterCollection>
  • Restarts a specific cluster

    Parameters

    • clusterID: number

      ID of the cluster to restart

    • Optional hard: boolean

      Whether to ignore the soft shutdown function

    Returns Promise<undefined | ClusterCollection>

    Promise which resolves with the cluster object when it restarts

  • restartService(serviceName: string, hard?: boolean): Promise<undefined | ServiceCollection>
  • Restarts a specific service

    Parameters

    • serviceName: string

      Name of the service

    • Optional hard: boolean

      Whether to ignore the soft shutdown function

    Returns Promise<undefined | ServiceCollection>

    Promise which resolves with the service object when it restarts

  • sendLog(type: "log" | "info" | "error" | "warn" | "debug", value: unknown, source?: string): void
  • Parameters

    • type: "log" | "info" | "error" | "warn" | "debug"
    • value: unknown
    • Optional source: string

    Returns void

  • sendTo(cluster: number, op: string, message?: unknown): void
  • Send a message to a specific cluster. The event can be listened to with register

    example
    this.ipc.sendTo(1, "Hello cluster 1!", "Squad up?");
    

    Parameters

    • cluster: number

      ID of the cluster

    • op: string

      Name of the event

    • Optional message: unknown

      Message to send

    Returns void

  • sendToAdmiral(op: string, message?: unknown): void
  • Send to the master process. The event can be listened to using Admiral.on("event", listener);

    example
    this.ipc.sendToAdmiral("Hello", "I'm working!");
    

    Parameters

    • op: string

      Name of the event

    • Optional message: unknown

      Message to send

    Returns void

  • serviceCommand(service: string, message?: unknown, receptive?: boolean, returnTimeout?: number): void | Promise<any>
  • Execute a service command

    example
    this.ipc.serviceCommand("ServiceName", "hello service!", true)
    .then((message) => console.log(message))
    .catch((error) => this.ipc.error(error));

    Parameters

    • service: string

      Name of the service

    • Optional message: unknown

      Whatever message you want to send with the command (defaults to null)

    • Optional receptive: boolean

      Whether you expect something to be returned to you from the command (defaults to false)

    • Optional returnTimeout: number

      How long to wait for a return (defaults to options.fetchTimeout)

    Returns void | Promise<any>

    Promise with data if receptive = true

  • serviceEval(serviceName: string, stringToEvaluate: string, receptive?: boolean, returnTimeout?: number): void | Promise<any>
  • Sends an eval to the mentioned service. The eval occurs from a function within the BaseServiceWorker class. NOTE: Use evals sparingly as they are a major security risk

    example
    this.ipc.serviceEval(1, "return 'hey!'", true)
    .then((data) => this.ipc.log(data))
    .catch((error) => this.ipc.error(error));

    Parameters

    • serviceName: string

      Name of the service

    • stringToEvaluate: string

      String to send to eval

    • Optional receptive: boolean

      Whether you expect something to be returned to you from the command (defaults to false)

    • Optional returnTimeout: number

      How long to wait for a return (defaults to options.fetchTimeout)

    Returns void | Promise<any>

    Promise with result if receptive = true

  • setMaxListeners(n: number): IPC
  • Parameters

    • n: number

    Returns IPC

  • shutdownCluster(clusterID: number, hard?: boolean): Promise<undefined | ClusterCollection>
  • Shuts down a cluster

    Parameters

    • clusterID: number

      The ID of the cluster to shutdown

    • Optional hard: boolean

      Whether to ignore the soft shutdown function

    Returns Promise<undefined | ClusterCollection>

    Promise which resolves with the cluster object when it shuts down

  • shutdownService(serviceName: string, hard?: boolean): Promise<undefined | ServiceCollection>
  • Shuts down a service

    Parameters

    • serviceName: string

      The name of the service

    • Optional hard: boolean

      Whether to ignore the soft shutdown function

    Returns Promise<undefined | ServiceCollection>

    Promise which resolves with the service object when it shuts down

  • totalShutdown(hard?: boolean): void
  • Shuts down everything and exits the master process

    Parameters

    • Optional hard: boolean

      Whether to ignore the soft shutdown function

    Returns void

  • unregister(event: string, callback?: (msg: any) => void): void
  • Unregisters an event

    example
    this.ipc.unregister("stats");
    

    Parameters

    • event: string

      Name of the event

    • Optional callback: (msg: any) => void

      Function which was listening. Leave empty if you want to delete all listeners registered to this event name.

        • (msg: any): void
        • Parameters

          • msg: any

          Returns void

    Returns void

  • warn(message: unknown, source?: string): void
  • Sends a warn log to the Admiral

    example
    this.ipc.warn("uh oh!");
    

    Parameters

    • message: unknown

      Item to log

    • Optional source: string

      Custom error source

    Returns void

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

  • on(emitter: EventEmitter, event: string): AsyncIterableIterator<any>
  • Parameters

    • emitter: EventEmitter
    • event: string

    Returns AsyncIterableIterator<any>

  • once(emitter: NodeEventTarget, event: string | symbol): Promise<any[]>
  • once(emitter: DOMEventTarget, event: string): Promise<any[]>
  • Parameters

    • emitter: NodeEventTarget
    • event: string | symbol

    Returns Promise<any[]>

  • Parameters

    • emitter: DOMEventTarget
    • event: string

    Returns Promise<any[]>

Generated using TypeDoc