on(event: 'error', handler: ErrorHandler<this>): void
on(event: 'online', handler: OnlineHandler<this>): void
on(event: 'exit', handler: ExitHandler<this>): void
+ once(event: 'exit', handler: ExitHandler<this>): void
}
/**
}
public async destroy (): Promise<void> {
- for (const worker of this.workers) {
- await this.destroyWorker(worker)
- }
+ await Promise.all(this.workers.map(worker => this.destroyWorker(worker)))
}
/**
worker.on('error', this.opts.errorHandler ?? (() => {}))
worker.on('online', this.opts.onlineHandler ?? (() => {}))
- // TODO handle properly when a worker exit
worker.on('exit', this.opts.exitHandler ?? (() => {}))
+ worker.once('exit', () => this.removeWorker(worker))
this.workers.push(worker)
protected destroyWorker (worker: Worker): void {
worker.kill()
- // FIXME: The tests are currently failing, so these must be changed first
}
protected sendToWorker (worker: Worker, message: MessageValue<Data>): void {