From: Jérôme Benoit Date: Wed, 13 Dec 2023 10:27:30 +0000 (+0100) Subject: fix: fix possible null exception with worker_threads pools X-Git-Tag: v3.0.14~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=fa548cda5120ac0708d82f37cd0ce1260d7f96c1;p=poolifier.git fix: fix possible null exception with worker_threads pools Signed-off-by: Jérôme Benoit --- diff --git a/CHANGELOG.md b/CHANGELOG.md index ddfd15e0..3ba761e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix possible null exception with worker_threads pools. + ## [3.0.13] - 2023-12-12 ### Fixed diff --git a/src/pools/thread/fixed.ts b/src/pools/thread/fixed.ts index 73740baa..28f8fceb 100644 --- a/src/pools/thread/fixed.ts +++ b/src/pools/thread/fixed.ts @@ -81,9 +81,7 @@ export class FixedThreadPool< message: MessageValue, transferList?: TransferListItem[] ): void { - ( - this.workerNodes[workerNodeKey]?.messageChannel as MessageChannel - )?.port1?.postMessage( + this.workerNodes[workerNodeKey].messageChannel?.port1?.postMessage( { ...message, workerId: this.getWorkerInfo(workerNodeKey).id }, transferList ) @@ -109,9 +107,10 @@ export class FixedThreadPool< workerNodeKey: number, listener: (message: MessageValue) => void ): void { - ( - this.workerNodes[workerNodeKey]?.messageChannel as MessageChannel - ).port1.on('message', listener) + this.workerNodes[workerNodeKey].messageChannel?.port1?.on( + 'message', + listener + ) } /** @inheritDoc */ @@ -119,9 +118,10 @@ export class FixedThreadPool< workerNodeKey: number, listener: (message: MessageValue) => void ): void { - ( - this.workerNodes[workerNodeKey]?.messageChannel as MessageChannel - ).port1.once('message', listener) + this.workerNodes[workerNodeKey].messageChannel?.port1?.once( + 'message', + listener + ) } /** @inheritDoc */ @@ -129,9 +129,10 @@ export class FixedThreadPool< workerNodeKey: number, listener: (message: MessageValue) => void ): void { - ( - this.workerNodes[workerNodeKey]?.messageChannel as MessageChannel - ).port1.off('message', listener) + this.workerNodes[workerNodeKey].messageChannel?.port1?.off( + 'message', + listener + ) } /** @inheritDoc */