import type { Worker } from 'cluster'
import type { MessagePort } from 'worker_threads'
import type { MessageValue } from '../utility-types'
+import { EMPTY_FUNCTION } from '../utils'
import type { KillBehavior, WorkerOptions } from './worker-options'
import { KillBehaviors } from './worker-options'
*
* @param fn The function that should be defined.
*/
- private checkFunctionInput (fn: (data: Data) => Response) {
+ private checkFunctionInput (fn: (data: Data) => Response): void {
if (!fn) throw new Error('fn parameter is mandatory')
}
try {
const res = fn(value.data)
this.sendToMainWorker({ data: res, id: value.id })
- this.lastTask = Date.now()
} catch (e) {
const err = this.handleError(e)
this.sendToMainWorker({ error: err, id: value.id })
+ } finally {
this.lastTask = Date.now()
}
}
fn(value.data)
.then(res => {
this.sendToMainWorker({ data: res, id: value.id })
- this.lastTask = Date.now()
return null
})
.catch(e => {
const err = this.handleError(e)
this.sendToMainWorker({ error: err, id: value.id })
+ })
+ .finally(() => {
this.lastTask = Date.now()
})
+ .catch(EMPTY_FUNCTION)
}
}