+ /** @inheritdoc */
+ public isDynamic (): boolean {
+ return false
+ }
+
+ /** @inheritdoc */
+ public setWorkerChoiceStrategy (
+ workerChoiceStrategy: WorkerChoiceStrategy
+ ): void {
+ this.opts.workerChoiceStrategy = workerChoiceStrategy
+ this.workerChoiceStrategyContext.setWorkerChoiceStrategy(
+ workerChoiceStrategy
+ )
+ }
+
+ /** @inheritdoc */
+ public execute (data: Data): Promise<Response> {
+ // Configure worker to handle message with the specified task
+ const worker = this.chooseWorker()
+ this.increaseWorkersTask(worker)
+ const messageId = ++this.nextMessageId
+ const res = this.internalExecute(worker, messageId)
+ this.sendToWorker(worker, { data: data || ({} as Data), id: messageId })
+ return res
+ }
+
+ /** @inheritdoc */
+ public async destroy (): Promise<void> {
+ await Promise.all(this.workers.map(worker => this.destroyWorker(worker)))
+ }
+
+ /** @inheritdoc */
+ public abstract destroyWorker (worker: Worker): void | Promise<void>
+
+ /**
+ * Setup hook that can be overridden by a Poolifier pool implementation
+ * to run code before workers are created in the abstract constructor.
+ */