fix: fix worker function type definition and validation
[poolifier.git] / src / worker / cluster-worker.ts
index 4f5fbb6b2ea87dcb54227b6b06576d80dba9c849..1d2729812f905d9f9724e5bf9106358ae8aa893a 100644 (file)
@@ -1,5 +1,5 @@
-import type { Worker } from 'cluster'
-import cluster from 'cluster'
+import type { Worker } from 'node:cluster'
+import cluster from 'node:cluster'
 import type { MessageValue } from '../utility-types'
 import { AbstractWorker } from './abstract-worker'
 import type { WorkerOptions } from './worker-options'
@@ -28,7 +28,10 @@ export class ClusterWorker<
    * @param fn - Function 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 (
+    fn: (data: Data) => Response | Promise<Response>,
+    opts: WorkerOptions = {}
+  ) {
     super(
       'worker-cluster-pool:poolifier',
       cluster.isPrimary,
@@ -38,12 +41,12 @@ export class ClusterWorker<
     )
   }
 
-  /** {@inheritDoc} */
+  /** @inheritDoc */
   protected sendToMainWorker (message: MessageValue<Response>): void {
     this.getMainWorker().send(message)
   }
 
-  /** {@inheritDoc} */
+  /** @inheritDoc */
   protected handleError (e: Error | string): string {
     return e instanceof Error ? e.message : e
   }