- protected sendToMainWorker (message: MessageValue<Response>): void {
- this.getMainWorker().postMessage(message)
+ protected handleReadyMessage (message: MessageValue<Data>): void {
+ if (
+ message.workerId === this.id &&
+ message.ready === false &&
+ message.port != null
+ ) {
+ try {
+ this.port = message.port
+ this.port.on('message', this.messageListener.bind(this))
+ this.sendToMainWorker({
+ ready: true,
+ taskFunctionsProperties: this.listTaskFunctionsProperties()
+ })
+ } catch {
+ this.sendToMainWorker({
+ ready: false,
+ taskFunctionsProperties: this.listTaskFunctionsProperties()
+ })
+ }
+ }
+ }
+
+ /** @inheritDoc */
+ protected handleKillMessage (message: MessageValue<Data>): void {
+ super.handleKillMessage(message)
+ this.port?.unref()
+ this.port?.close()
+ }
+
+ /** @inheritDoc */
+ protected get id (): number {
+ return threadId
+ }
+
+ /** @inheritDoc */
+ protected readonly sendToMainWorker = (
+ message: MessageValue<Response>
+ ): void => {
+ this.port?.postMessage({
+ ...message,
+ workerId: this.id
+ } satisfies MessageValue<Response>)
+ }
+
+ /**
+ * @inheritDoc
+ * @override
+ */
+ protected handleError (error: Error | string): string {
+ return error as string