import type { Worker } from 'cluster'
import type { MessagePort } from 'worker_threads'
import type { MessageValue } from '../utility-types'
import type { Worker } from 'cluster'
import type { MessagePort } from 'worker_threads'
import type { MessageValue } from '../utility-types'
import type { KillBehavior, WorkerOptions } from './worker-options'
import { KillBehaviors } from './worker-options'
import type { KillBehavior, WorkerOptions } from './worker-options'
import { KillBehaviors } from './worker-options'
* Base class containing some shared logic for all poolifier workers.
*
* @template MainWorker Type of main worker.
* Base class containing some shared logic for all poolifier workers.
*
* @template MainWorker Type of main worker.
- * @template Data Type of data this worker receives from pool's execution.
- * @template Response Type of response the worker sends back to the main worker.
+ * @template Data Type of data this worker receives from pool's execution. This can only be serializable data.
+ * @template Response Type of response the worker sends back to the main worker. This can only be serializable data.
*/
export abstract class AbstractWorker<
MainWorker extends Worker | MessagePort,
*/
export abstract class AbstractWorker<
MainWorker extends Worker | MessagePort,
try {
const res = fn(value.data)
this.sendToMainWorker({ data: res, id: value.id })
try {
const res = fn(value.data)
this.sendToMainWorker({ data: res, id: value.id })
} catch (e) {
const err = this.handleError(e)
this.sendToMainWorker({ error: err, id: value.id })
} catch (e) {
const err = this.handleError(e)
this.sendToMainWorker({ error: err, id: value.id })
return null
})
.catch(e => {
const err = this.handleError(e)
this.sendToMainWorker({ error: err, id: value.id })
return null
})
.catch(e => {
const err = this.handleError(e)
this.sendToMainWorker({ error: err, id: value.id })