X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fthread-worker.ts;h=d6a3699220b63fad5dc3191c1b4c1ca72d112bc8;hb=37b32d84b2a0d8f8addad8c5e6a306c7dd22d58d;hp=e208eb4063656dccf1ed25a8c12463c6de1302e5;hpb=29d8b961b1907797d251871a97092973d342c63c;p=poolifier.git diff --git a/src/worker/thread-worker.ts b/src/worker/thread-worker.ts index e208eb40..d6a36992 100644 --- a/src/worker/thread-worker.ts +++ b/src/worker/thread-worker.ts @@ -54,12 +54,24 @@ export class ThreadWorker< protected handleReadyMessage (message: MessageValue): void { if ( message.workerId === this.id && - message.ready != null && + message.ready === false && message.port != null ) { - this.port = message.port - this.port.on('message', this.messageListener.bind(this)) - this.sendToMainWorker({ ready: true, workerId: this.id }) + try { + this.port = message.port + this.port.on('message', this.messageListener.bind(this)) + this.sendToMainWorker({ + ready: true, + taskFunctions: this.listTaskFunctions(), + workerId: this.id + }) + } catch { + this.sendToMainWorker({ + ready: false, + taskFunctions: this.listTaskFunctions(), + workerId: this.id + }) + } } } @@ -81,7 +93,7 @@ export class ThreadWorker< } /** @inheritDoc */ - protected handleError (e: Error | string): string { - return e as string + protected handleError (error: Error | string): string { + return error as string } }