Fix sonar code smells (#184)
[poolifier.git] / src / worker / abstract-worker.ts
index 6aa34e8e899fda868bf0c1935b656a21d8b67629..03d954fe62f1933594e4f556511e9762b7093fb5 100644 (file)
@@ -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.
    *