X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fcluster-worker.ts;h=2a3961b37f02836d52c7972f98ee150c02904281;hb=1c6fe997dcb16b510da6587b992cd3f66d62a259;hp=43e86dd751a5cf8f17a35bbc40185c1ab978920a;hpb=fc3e65861bc1939ae047ee1e8e91a1ce577035f4;p=poolifier.git diff --git a/src/worker/cluster-worker.ts b/src/worker/cluster-worker.ts index 43e86dd7..2a3961b3 100644 --- a/src/worker/cluster-worker.ts +++ b/src/worker/cluster-worker.ts @@ -1,8 +1,8 @@ -import type { Worker } from 'node:cluster' -import cluster from 'node:cluster' +import cluster, { type Worker } from 'node:cluster' import type { MessageValue } from '../utility-types' import { AbstractWorker } from './abstract-worker' import type { WorkerOptions } from './worker-options' +import type { TaskFunctions, WorkerFunction } from './worker-functions' /** * A cluster worker used by a poolifier `ClusterPool`. @@ -25,25 +25,30 @@ export class ClusterWorker< /** * Constructs a new poolifier cluster worker. * - * @param fn - Function processed by the worker when the pool's `execution` function is invoked. + * @param taskFunctions - Task function(s) processed by the worker when the pool's `execution` function is invoked. * @param opts - Options for the worker. */ - public constructor (fn: (data: Data) => Response, opts: WorkerOptions = {}) { + public constructor ( + taskFunctions: + | WorkerFunction + | TaskFunctions, + opts: WorkerOptions = {} + ) { super( 'worker-cluster-pool:poolifier', cluster.isPrimary, - fn, + taskFunctions, cluster.worker, opts ) } - /** {@inheritDoc} */ + /** @inheritDoc */ protected sendToMainWorker (message: MessageValue): void { this.getMainWorker().send(message) } - /** {@inheritDoc} */ + /** @inheritDoc */ protected handleError (e: Error | string): string { return e instanceof Error ? e.message : e }