Bump eslint-plugin-jsdoc from 32.0.2 to 32.1.0 (#212)
[poolifier.git] / src / worker / abstract-worker.ts
index 6aa34e8e899fda868bf0c1935b656a21d8b67629..d41115bc390b26f63eeaa9ae4500d678cb1bd7b4 100644 (file)
@@ -12,8 +12,8 @@ const DEFAULT_KILL_BEHAVIOR: KillBehavior = KillBehaviors.SOFT
  * 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,
@@ -66,7 +66,7 @@ export abstract class AbstractWorker<
       this.opts.maxInactiveTime ?? DEFAULT_MAX_INACTIVE_TIME
     this.async = !!this.opts.async
     this.lastTask = Date.now()
-    if (!fn) throw new Error('fn parameter is mandatory')
+    this.checkFunctionInput(fn)
     // Keep the worker active
     if (!isMain) {
       this.interval = setInterval(
@@ -96,6 +96,15 @@ export abstract class AbstractWorker<
     })
   }
 
+  /**
+   * Check if the `fn` parameter is passed to the constructor.
+   *
+   * @param fn The function that should be defined.
+   */
+  private checkFunctionInput (fn: (data: Data) => Response) {
+    if (!fn) throw new Error('fn parameter is mandatory')
+  }
+
   /**
    * Returns the main worker.
    *