- public async destroyWorker (
- worker: ThreadWorkerWithMessageChannel
- ): Promise<void> {
- this.sendToWorker(worker, { kill: 1 })
- await worker.terminate()
+ protected sendToWorker (
+ workerNodeKey: number,
+ message: MessageValue<Data>,
+ transferList?: TransferListItem[]
+ ): void {
+ this.workerNodes[workerNodeKey].messageChannel?.port1?.postMessage(
+ { ...message, workerId: this.getWorkerInfo(workerNodeKey).id },
+ transferList
+ )
+ }
+
+ /** @inheritDoc */
+ protected sendStartupMessageToWorker (workerNodeKey: number): void {
+ const workerNode = this.workerNodes[workerNodeKey]
+ const port2: MessagePort = (workerNode.messageChannel as MessageChannel)
+ .port2
+ workerNode.worker.postMessage(
+ {
+ ready: false,
+ workerId: this.getWorkerInfo(workerNodeKey).id,
+ port: port2
+ },
+ [port2]
+ )