X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fabstract-worker.ts;h=fbf99ab8f1dfffe8936b4f25140c3d9597772d3b;hb=41aa7dcd8bbc5ff5a5aefe8765fe8a7c57d6be00;hp=5390ec029719549aeef5c31791b22e3365eeaa4c;hpb=526c970b0ea1dcb83aab8eb1715f5c60d534bcdf;p=poolifier.git diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 5390ec02..fbf99ab8 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -80,6 +80,30 @@ export abstract class AbstractWorker< ) } + private checkWorkerOptions (opts: WorkerOptions): void { + this.opts.killBehavior = opts.killBehavior ?? DEFAULT_KILL_BEHAVIOR + this.opts.maxInactiveTime = + opts.maxInactiveTime ?? DEFAULT_MAX_INACTIVE_TIME + this.opts.async = opts.async ?? false + } + + /** + * Checks if the `fn` parameter is passed to the constructor. + * + * @param fn - The function that should be defined. + */ + private checkFunctionInput (fn: WorkerFunction): void { + if (fn == null) throw new Error('fn parameter is mandatory') + if (typeof fn !== 'function') { + throw new TypeError('fn parameter is not a function') + } + if (fn.constructor.name === 'AsyncFunction' && this.opts.async === false) { + throw new Error( + 'fn parameter is an async function, please set the async option to true' + ) + } + } + /** * Worker message listener. * @@ -107,30 +131,6 @@ export abstract class AbstractWorker< } } - private checkWorkerOptions (opts: WorkerOptions): void { - this.opts.killBehavior = opts.killBehavior ?? DEFAULT_KILL_BEHAVIOR - this.opts.maxInactiveTime = - opts.maxInactiveTime ?? DEFAULT_MAX_INACTIVE_TIME - this.opts.async = opts.async ?? false - } - - /** - * Checks if the `fn` parameter is passed to the constructor. - * - * @param fn - The function that should be defined. - */ - private checkFunctionInput (fn: WorkerFunction): void { - if (fn == null) throw new Error('fn parameter is mandatory') - if (typeof fn !== 'function') { - throw new TypeError('fn parameter is not a function') - } - if (fn.constructor.name === 'AsyncFunction' && this.opts.async === false) { - throw new Error( - 'fn parameter is an async function, please set the async option to true' - ) - } - } - /** * Returns the main worker. *