*/
protected lastTaskTimestamp!: number
/**
- * Performance statistics computation.
+ * Performance statistics computation requirements.
*/
protected statistics!: WorkerStatistics
/**
} 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
}
}
}
private beginTaskPerformance (): TaskPerformance {
+ this.checkStatistics()
return {
timestamp: performance.now(),
...(this.statistics.elu && { elu: performance.eventLoopUtilization() })
private endTaskPerformance (
taskPerformance: TaskPerformance
): TaskPerformance {
+ this.checkStatistics()
return {
...taskPerformance,
...(this.statistics.runTime && {
})
}
}
+
+ private checkStatistics (): void {
+ if (this.statistics == null) {
+ throw new Error('Performance statistics computation requirements not set')
+ }
+ }
}