+ this.checkNumberOfWorkers(this.numberOfWorkers)
+ this.checkFilePath(this.filePath)
+ this.checkPoolOptions(this.opts)
+
+ this.chooseWorker.bind(this)
+ this.internalExecute.bind(this)
+ this.checkAndEmitFull.bind(this)
+ this.checkAndEmitBusy.bind(this)
+ this.sendToWorker.bind(this)
+
+ this.setupHook()
+
+ for (let i = 1; i <= this.numberOfWorkers; i++) {
+ this.createAndSetupWorker()
+ }
+
+ if (this.opts.enableEvents === true) {
+ this.emitter = new PoolEmitter()
+ }
+ this.workerChoiceStrategyContext = new WorkerChoiceStrategyContext<
+ Worker,
+ Data,
+ Response
+ >(
+ this,
+ () => {
+ const createdWorker = this.createAndSetupWorker()
+ this.registerWorkerMessageListener(createdWorker, message => {
+ if (
+ isKillBehavior(KillBehaviors.HARD, message.kill) ||
+ this.getWorkerTasksUsage(createdWorker)?.running === 0
+ ) {
+ // Kill received from the worker, means that no new tasks are submitted to that worker for a while ( > maxInactiveTime)
+ void this.destroyWorker(createdWorker)
+ }
+ })
+ return this.getWorkerKey(createdWorker)
+ },
+ this.opts.workerChoiceStrategy
+ )
+ }
+
+ private checkFilePath (filePath: string): void {
+ if (
+ filePath == null ||
+ (typeof filePath === 'string' && filePath.trim().length === 0)
+ ) {