/**
* Performance statistics computation requirements.
*/
- protected statistics!: WorkerStatistics
+ protected statistics?: WorkerStatistics
/**
* Handler id of the `activeInterval` worker activity check.
*/
* @param opts - Options for the worker.
*/
public constructor (
- protected readonly isMain: boolean,
- private readonly mainWorker: MainWorker,
+ protected readonly isMain: boolean | undefined,
+ private readonly mainWorker: MainWorker | undefined | null,
taskFunctions: TaskFunction<Data, Response> | TaskFunctions<Data, Response>,
protected opts: WorkerOptions = DEFAULT_WORKER_OPTIONS
) {
* @param taskFunctions - The task function(s) parameter that should be checked.
*/
private checkTaskFunctions (
- taskFunctions: TaskFunction<Data, Response> | TaskFunctions<Data, Response>
+ taskFunctions:
+ | TaskFunction<Data, Response>
+ | TaskFunctions<Data, Response>
+ | undefined
): void {
if (taskFunctions == null) {
throw new Error('taskFunctions parameter is mandatory')
taskFunctionOperationStatus: response.status,
taskFunctionName,
...(!response.status &&
- response?.error != null && {
+ response.error != null && {
workerError: {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
name: taskFunctionName!,
protected handleKillMessage (_message: MessageValue<Data>): void {
this.stopCheckActive()
if (isAsyncFunction(this.opts.killHandler)) {
- (this.opts.killHandler?.() as Promise<void>)
+ (this.opts.killHandler() as Promise<void>)
.then(() => {
this.sendToMainWorker({ kill: 'success' })
return undefined
workerError: {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
name: name!,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- message: `Task function '${name!}' not found`,
+ message: `Task function '${name}' not found`,
data
},
taskId
}
private beginTaskPerformance (name?: string): TaskPerformance {
- this.checkStatistics()
+ if (this.statistics == null) {
+ throw new Error('Performance statistics computation requirements not set')
+ }
return {
name: name ?? DEFAULT_TASK_NAME,
timestamp: performance.now(),
- ...(this.statistics.elu && { elu: performance.eventLoopUtilization() })
+ ...(this.statistics.elu && {
+ elu: performance.eventLoopUtilization()
+ })
}
}
private endTaskPerformance (
taskPerformance: TaskPerformance
): TaskPerformance {
- this.checkStatistics()
+ if (this.statistics == null) {
+ throw new Error('Performance statistics computation requirements not set')
+ }
return {
...taskPerformance,
...(this.statistics.runTime && {
}
}
- private checkStatistics (): void {
- if (this.statistics == null) {
- throw new Error('Performance statistics computation requirements not set')
- }
- }
-
private updateLastTaskTimestamp (): void {
if (this.activeInterval != null) {
this.lastTaskTimestamp = performance.now()