- // eslint-disable-next-line spellcheck/spell-checker
- public get numWorkers (): number {
- return this.numberOfWorkers
+ 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
+ }
+
+ /**
+ * Shut down every current worker in this pool.
+ */
+ public async destroy (): Promise<void> {
+ await Promise.all(this.workers.map(worker => this.destroyWorker(worker)))