this.checkFunctionInput(fn)
this.checkWorkerOptions(this.opts)
if (!this.isMain) {
- this.lastTaskTimestamp = Date.now()
+ this.lastTaskTimestamp = performance.now()
this.aliveInterval = setInterval(
this.checkAlive.bind(this),
(this.opts.maxInactiveTime ?? DEFAULT_MAX_INACTIVE_TIME) / 2
*/
protected checkAlive (): void {
if (
- Date.now() - this.lastTaskTimestamp >
+ performance.now() - this.lastTaskTimestamp >
(this.opts.maxInactiveTime ?? DEFAULT_MAX_INACTIVE_TIME)
) {
this.sendToMainWorker({ kill: this.opts.killBehavior })
message: MessageValue<Data>
): void {
try {
- const startTimestamp = Date.now()
+ const startTimestamp = performance.now()
const res = fn(message.data)
- const runTime = Date.now() - startTimestamp
- this.sendToMainWorker({ data: res, id: message.id, runTime })
+ const runTime = performance.now() - startTimestamp
+ this.sendToMainWorker({
+ data: res,
+ id: message.id,
+ runTime
+ })
} catch (e) {
const err = this.handleError(e as Error)
this.sendToMainWorker({ error: err, id: message.id })
} finally {
- !this.isMain && (this.lastTaskTimestamp = Date.now())
+ !this.isMain && (this.lastTaskTimestamp = performance.now())
}
}
fn: (data?: Data) => Promise<Response>,
message: MessageValue<Data>
): void {
- const startTimestamp = Date.now()
+ const startTimestamp = performance.now()
fn(message.data)
.then(res => {
- const runTime = Date.now() - startTimestamp
- this.sendToMainWorker({ data: res, id: message.id, runTime })
+ const runTime = performance.now() - startTimestamp
+ this.sendToMainWorker({
+ data: res,
+ id: message.id,
+ runTime
+ })
return null
})
.catch(e => {
this.sendToMainWorker({ error: err, id: message.id })
})
.finally(() => {
- !this.isMain && (this.lastTaskTimestamp = Date.now())
+ !this.isMain && (this.lastTaskTimestamp = performance.now())
})
.catch(EMPTY_FUNCTION)
}