X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fabstract-pool.ts;h=6531d6615349bda3b7223329977963ee7eba95a5;hb=e5a5c0fc68a38b7d6316cc573c34313aa6ec30e9;hp=c2b54b58d0b24171f26c611d0655016afca29849;hpb=38e795c12f0e9daeff7b025147f36f85f486366e;p=poolifier.git diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index c2b54b58..6531d661 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -2,8 +2,8 @@ import type { MessageValue, PromiseWorkerResponseWrapper } from '../utility-types' -import { EMPTY_FUNCTION, EMPTY_LITERAL } from '../utils' -import { isKillBehavior, KillBehaviors } from '../worker/worker-options' +import { EMPTY_FUNCTION } from '../utils' +import { KillBehaviors, isKillBehavior } from '../worker/worker-options' import type { PoolOptions } from './pool' import { PoolEmitter } from './pool' import type { IPoolInternal, TasksUsage } from './pool-internal' @@ -11,7 +11,7 @@ import { PoolType } from './pool-internal' import type { IPoolWorker } from './pool-worker' import { WorkerChoiceStrategies, - WorkerChoiceStrategy + type WorkerChoiceStrategy } from './selection-strategies/selection-strategies-types' import { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context' @@ -208,7 +208,8 @@ export abstract class AbstractPool< const res = this.internalExecute(worker, this.nextMessageId) this.checkAndEmitBusy() this.sendToWorker(worker, { - data: data ?? (EMPTY_LITERAL as Data), + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions + data: data ?? ({} as Data), id: this.nextMessageId }) ++this.nextMessageId @@ -218,7 +219,11 @@ export abstract class AbstractPool< /** {@inheritDoc} */ public async destroy (): Promise { - await Promise.all(this.workers.map(worker => this.destroyWorker(worker))) + await Promise.all( + this.workers.map(async worker => { + await this.destroyWorker(worker) + }) + ) } /** @@ -336,7 +341,9 @@ export abstract class AbstractPool< worker.on('error', this.opts.errorHandler ?? EMPTY_FUNCTION) worker.on('online', this.opts.onlineHandler ?? EMPTY_FUNCTION) worker.on('exit', this.opts.exitHandler ?? EMPTY_FUNCTION) - worker.once('exit', () => this.removeWorker(worker)) + worker.once('exit', () => { + this.removeWorker(worker) + }) this.workers.push(worker)