- /** @inheritdoc */
- public destroyWorker (worker: Worker): void {
- this.sendToWorker(worker, { kill: 1 })
- worker.kill()
+ /** @inheritDoc */
+ protected async destroyWorkerNode (workerNodeKey: number): Promise<void> {
+ this.flushTasksQueue(workerNodeKey)
+ // FIXME: wait for tasks to be finished
+ const worker = this.workerNodes[workerNodeKey].worker
+ const waitWorkerExit = new Promise<void>((resolve) => {
+ worker.on('exit', () => {
+ resolve()
+ })
+ })
+ worker.on('disconnect', () => {
+ worker.kill()
+ })
+ await this.sendKillMessageToWorker(workerNodeKey, worker.id)
+ worker.disconnect()
+ await waitWorkerExit
+ }
+
+ /** @inheritDoc */
+ protected sendToWorker (
+ workerNodeKey: number,
+ message: MessageValue<Data>
+ ): void {
+ this.workerNodes[workerNodeKey].worker.send(message)