Class BaseServiceWorker<LibLatencyRef>

The base class for a service

Example

const { BaseServiceWorker } = require('eris-fleet');

module.exports = class ServiceWorker extends BaseServiceWorker {
constructor(setup) {
// Do not delete this super.
super(setup);

// Run this function when your service is ready for use. This MUST be run for the worker spawning to continue.
this.serviceReady();

// Demonstration of the properties the service has (Keep reading for info on IPC):
// ID of the worker
console.log(this.workerID);
// The name of the service
console.log(this.serviceName);
}
// This is the function which will handle commands. In this example the data is {"smileyFace": ":)"}
async handleCommand(dataSentInCommand) {
// Return a response if you want to respond
return dataSentInCommand.smileyFace;
}
shutdown(done) {
// Optional function to gracefully shutdown things if you need to.
done(); // Use this function when you are done gracefully shutting down.
}
}

Type Parameters

  • LibLatencyRef

Hierarchy

  • BaseServiceWorker

Constructors

Properties

ipc: IPC<LibLatencyRef>
serviceName: string

Unique name given to the service

serviceReady: (() => void)

Type declaration

    • (): void
    • Function to report a service being ready

      Returns void

serviceStartingError: ((error) => void)

Type declaration

    • (error): void
    • Function to report error during service launch

      Parameters

      • error: unknown

        Error to report

      Returns void

workerID: number

ID of the worker

Methods

  • Graceful shutdown of the service. Have a function within your bot class called shutdown to use this.

    To handle errors, return something similar to the following: {err: "error here"}

    See

    BaseServiceWorker See for an example

    Parameters

    • done: (() => void)

      Call this function when your shutdown function is complete.

        • (): void
        • Returns void

    Returns void

Generated using TypeDoc