X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fabstract-pool.ts;h=1bd5ee2cc73152e912cc08ecc3492f8e4a9ae6b7;hb=e4c07d066abc51e978a18f44a973a548f24fb7ad;hp=7be2cef51c8f11646b5f43174de7abe3ea43a82c;hpb=037af3175d6121a6c08a631c992aa0d7fe853a9f;p=poolifier.git diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 7be2cef5..1bd5ee2c 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -846,13 +846,22 @@ export abstract class AbstractPool< /** @inheritDoc */ public async addTaskFunction ( name: string, - taskFunction: TaskFunction + fn: TaskFunction ): Promise { - this.taskFunctions.set(name, taskFunction) + if (typeof name !== 'string') { + throw new TypeError('name argument must be a string') + } + if (typeof name === 'string' && name.trim().length === 0) { + throw new TypeError('name argument must not be an empty string') + } + if (typeof fn !== 'function') { + throw new TypeError('fn argument must be a function') + } + this.taskFunctions.set(name, fn) return await this.sendTaskFunctionOperationToWorkers({ taskFunctionOperation: 'add', taskFunctionName: name, - taskFunction: taskFunction.toString() + taskFunction: fn.toString() }) } @@ -860,7 +869,7 @@ export abstract class AbstractPool< public async removeTaskFunction (name: string): Promise { if (!this.taskFunctions.has(name)) { throw new Error( - 'Cannot remove a task function that does not exist on the pool side' + 'Cannot remove a task function not handled on the pool side' ) } this.taskFunctions.delete(name)