- const err = this.handleError(e)
- this.sendToMainWorker({ error: err, id: value.id })
- this.lastTask = Date.now()
+ const err = this.handleError(e as Error)
+ this.sendToMainWorker({
+ error: err,
+ errorData: message.data,
+ id: message.id
+ })
+ })
+ .finally(() => {
+ !this.isMain && (this.lastTaskTimestamp = performance.now())
+ })
+ .catch(EMPTY_FUNCTION)
+ }
+
+ /**
+ * Gets the task function in the given scope.
+ *
+ * @param name - Name of the function that will be returned.
+ */
+ private getTaskFunction (name?: string): WorkerFunction<Data, Response> {
+ name = name ?? DEFAULT_FUNCTION_NAME
+ const fn = this.taskFunctions.get(name)
+ if (fn == null) {
+ throw new Error(`Task function '${name}' not found`)
+ }
+ return fn
+ }
+
+ private beginTaskPerformance (message: MessageValue<Data>): TaskPerformance {
+ const timestamp = performance.now()
+ return {
+ timestamp,
+ ...(this.statistics.waitTime && {
+ waitTime: timestamp - (message.timestamp ?? timestamp)
+ }),
+ ...(this.statistics.elu && { elu: performance.eventLoopUtilization() })
+ }
+ }
+
+ private endTaskPerformance (
+ taskPerformance: TaskPerformance
+ ): TaskPerformance {
+ return {
+ ...taskPerformance,
+ ...(this.statistics.runTime && {
+ runTime: performance.now() - taskPerformance.timestamp
+ }),
+ ...(this.statistics.elu && {
+ elu: performance.eventLoopUtilization(taskPerformance.elu)