protected createAndSetupWorkerNode (): number {
const worker = this.createWorker()
+ worker.on('online', this.opts.onlineHandler ?? EMPTY_FUNCTION)
worker.on('message', this.opts.messageHandler ?? EMPTY_FUNCTION)
worker.on('error', this.opts.errorHandler ?? EMPTY_FUNCTION)
worker.on('error', (error) => {
this.redistributeQueuedTasks(workerNodeKey)
}
})
- worker.on('online', this.opts.onlineHandler ?? EMPTY_FUNCTION)
worker.on('exit', this.opts.exitHandler ?? EMPTY_FUNCTION)
worker.once('exit', () => {
this.removeWorkerNode(worker)
* @typeParam Worker - Type of worker.
*/
export interface PoolOptions<Worker extends IWorker> {
+ /**
+ * A function that will listen for online event on each worker.
+ */
+ onlineHandler?: OnlineHandler<Worker>
/**
* A function that will listen for message event on each worker.
*/
* A function that will listen for error event on each worker.
*/
errorHandler?: ErrorHandler<Worker>
- /**
- * A function that will listen for online event on each worker.
- */
- onlineHandler?: OnlineHandler<Worker>
/**
* A function that will listen for exit event on each worker.
*/
* @param event - The event.
* @param handler - The event handler.
*/
- readonly on: ((event: 'message', handler: MessageHandler<this>) => void) &
+ readonly on: ((event: 'online', handler: OnlineHandler<this>) => void) &
+ ((event: 'message', handler: MessageHandler<this>) => void) &
((event: 'error', handler: ErrorHandler<this>) => void) &
- ((event: 'online', handler: OnlineHandler<this>) => void) &
((event: 'exit', handler: ExitHandler<this>) => void)
/**
* Registers a listener to the exit event that will only be performed once.