* Base class that implements some shared logic for all poolifier workers.
*
* @typeParam MainWorker - Type of main worker.
* Base class that implements some shared logic for all poolifier workers.
*
* @typeParam MainWorker - Type of main worker.
- * @typeParam Data - Type of data this worker receives from pool's execution. This can only be serializable data.
- * @typeParam Response - Type of response the worker sends back to the main worker. This can only be serializable data.
+ * @typeParam Data - Type of data this worker receives from pool's execution. This can only be structured-cloneable data.
+ * @typeParam Response - Type of response the worker sends back to the main worker. This can only be structured-cloneable data.
*/
export abstract class AbstractWorker<
MainWorker extends Worker | MessagePort,
Data = unknown,
Response = unknown
> extends AsyncResource {
*/
export abstract class AbstractWorker<
MainWorker extends Worker | MessagePort,
Data = unknown,
Response = unknown
> extends AsyncResource {
taskFunctions:
| WorkerFunction<Data, Response>
| TaskFunctions<Data, Response>,
taskFunctions:
| WorkerFunction<Data, Response>
| TaskFunctions<Data, Response>,
protected readonly opts: WorkerOptions = {
/**
* The kill behavior option on this worker or its default value.
protected readonly opts: WorkerOptions = {
/**
* The kill behavior option on this worker or its default value.
- protected messageListener (
- message: MessageValue<Data, Data, MainWorker>
- ): void {
+ protected messageListener (message: MessageValue<Data, Data>): void {
} else {
this.runInAsyncScope(this.runSync.bind(this), this, fn, message)
}
} else {
this.runInAsyncScope(this.runSync.bind(this), this, fn, message)
}
- } else if (message.parent != null) {
- // Main worker reference message received
- this.mainWorker = message.parent
+ } else if (message.statistics != null) {
+ // Statistics message received
+ this.statistics = message.statistics
* Handles an error and convert it to a string so it can be sent back to the main worker.
*
* @param e - The error raised by the worker.
* Handles an error and convert it to a string so it can be sent back to the main worker.
*
* @param e - The error raised by the worker.
return {
timestamp: performance.now(),
...(this.statistics.elu && { elu: performance.eventLoopUtilization() })
return {
timestamp: performance.now(),
...(this.statistics.elu && { elu: performance.eventLoopUtilization() })