this.checkWorkerOptions(this.opts)
this.lastTaskTimestamp = Date.now()
// Keep the worker active
- if (!isMain) {
+ if (isMain === false) {
this.aliveInterval = setInterval(
this.checkAlive.bind(this),
(this.opts.maxInactiveTime ?? DEFAULT_MAX_INACTIVE_TIME) / 2
value: MessageValue<Data>
): void {
try {
+ const startTaskTimestamp = Date.now()
const res = fn(value.data)
- this.sendToMainWorker({ data: res, id: value.id })
+ const taskRunTime = Date.now() - startTaskTimestamp
+ this.sendToMainWorker({ data: res, id: value.id, taskRunTime })
} catch (e) {
const err = this.handleError(e as Error)
this.sendToMainWorker({ error: err, id: value.id })
fn: (data?: Data) => Promise<Response>,
value: MessageValue<Data>
): void {
+ const startTaskTimestamp = Date.now()
fn(value.data)
.then(res => {
- this.sendToMainWorker({ data: res, id: value.id })
+ const taskRunTime = Date.now() - startTaskTimestamp
+ this.sendToMainWorker({ data: res, id: value.id, taskRunTime })
return null
})
.catch(e => {