X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fworker-node.ts;h=09e4a7b5cd8831360365a7a88e338e3b921eaf91;hb=8735b4e51c0cfabc9612d57417834d42042cab4e;hp=7667dd16a6b99c2994eaeda37866662b43f8d178;hpb=d5e3c4fff00e3ef76442041c6e0a6d01a2b24650;p=poolifier.git diff --git a/src/pools/worker-node.ts b/src/pools/worker-node.ts index 7667dd16..09e4a7b5 100644 --- a/src/pools/worker-node.ts +++ b/src/pools/worker-node.ts @@ -40,6 +40,22 @@ implements IWorkerNode { * @param poolMaxSize - The pool maximum size. */ constructor (worker: Worker, workerType: WorkerType, poolMaxSize: number) { + if (worker == null) { + throw new Error('Cannot construct a worker node without a worker') + } + if (workerType == null) { + throw new Error('Cannot construct a worker node without a worker type') + } + if (poolMaxSize == null) { + throw new Error( + 'Cannot construct a worker node without a pool maximum size' + ) + } + if (isNaN(poolMaxSize)) { + throw new Error( + 'Cannot construct a worker node with a NaN pool maximum size' + ) + } this.worker = worker this.info = this.initWorkerInfo(worker, workerType) if (workerType === WorkerTypes.thread) { @@ -82,7 +98,7 @@ implements IWorkerNode { /** @inheritdoc */ public hasBackPressure (): boolean { - return this.tasksQueueSize() >= this.tasksQueueBackPressureSize + return this.tasksQueue.size >= this.tasksQueueBackPressureSize } /** @inheritdoc */