X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fabstract-worker.ts;h=03d954fe62f1933594e4f556511e9762b7093fb5;hb=c510fea7f620c9b406f1b3f655729ad83ed32c2b;hp=6aa34e8e899fda868bf0c1935b656a21d8b67629;hpb=eb3b4c1592abc3f91acfe98c236a02ca994febff;p=poolifier.git diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 6aa34e8e..03d954fe 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -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. *