X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fabstract-worker.ts;h=1e1d3088fb7cce28ad22f1961899786e6edd5fdd;hb=520c8c68ceeccd6b9f4cd363241fdd2c4d628234;hp=a84bb0691fc588d3a8e51b0fe1696d7c85bb7dc9;hpb=1c6fe997dcb16b510da6587b992cd3f66d62a259;p=poolifier.git diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index a84bb069..1e1d3088 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -45,7 +45,7 @@ export abstract class AbstractWorker< */ protected lastTaskTimestamp!: number /** - * Performance statistics computation. + * Performance statistics computation requirements. */ protected statistics!: WorkerStatistics /** @@ -160,13 +160,13 @@ export abstract class AbstractWorker< } else if (message.parent != null) { // Main worker reference message received this.mainWorker = message.parent + } else if (message.statistics != null) { + // Statistics message received + this.statistics = message.statistics } else if (message.kill != null) { // Kill message received this.aliveInterval != null && clearInterval(this.aliveInterval) this.emitDestroy() - } else if (message.statistics != null) { - // Statistics message received - this.statistics = message.statistics } } @@ -298,6 +298,7 @@ export abstract class AbstractWorker< } private beginTaskPerformance (): TaskPerformance { + this.checkStatistics() return { timestamp: performance.now(), ...(this.statistics.elu && { elu: performance.eventLoopUtilization() }) @@ -307,6 +308,7 @@ export abstract class AbstractWorker< private endTaskPerformance ( taskPerformance: TaskPerformance ): TaskPerformance { + this.checkStatistics() return { ...taskPerformance, ...(this.statistics.runTime && { @@ -317,4 +319,10 @@ export abstract class AbstractWorker< }) } } + + private checkStatistics (): void { + if (this.statistics == null) { + throw new Error('Performance statistics computation requirements not set') + } + } }