+ this.checkNumberOfWorkers(this.numberOfWorkers)
+ this.checkFilePath(this.filePath)
+ this.checkPoolOptions(this.opts)
+ this.setupHook()
+
+ for (let i = 1; i <= this.numberOfWorkers; i++) {
+ this.createAndSetupWorker()
+ }
+
+ if (this.opts.enableEvents) {
+ this.emitter = new PoolEmitter()
+ }
+ this.workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
+ this,
+ () => {
+ const workerCreated = this.createAndSetupWorker()
+ this.registerWorkerMessageListener(workerCreated, async message => {
+ const tasksInProgress = this.tasks.get(workerCreated)
+ if (
+ isKillBehavior(KillBehaviors.HARD, message.kill) ||
+ tasksInProgress === 0
+ ) {
+ // Kill received from the worker, means that no new tasks are submitted to that worker for a while ( > maxInactiveTime)
+ await this.destroyWorker(workerCreated)
+ }
+ })
+ return workerCreated
+ },
+ this.opts.workerChoiceStrategy
+ )
+ }
+
+ private checkFilePath (filePath: string): void {
+ if (!filePath) {