X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fabstract-pool.ts;h=b14801b69269b43cfe878dee88ef4987151dfb33;hb=55082af96253bead6fb8d4d648c454ba71a38fb6;hp=de37c0f9266cc6d6b6ca37fdd7c174ccd94afaec;hpb=4511441a7858ae4871037148b3c9505ac422f4f2;p=poolifier.git diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index de37c0f9..b14801b6 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -17,7 +17,6 @@ import { max, median, min, - once, round } from '../utils' import { KillBehaviors } from '../worker/worker-options' @@ -117,6 +116,10 @@ export abstract class AbstractPool< * Whether the pool is destroying or not. */ private destroying: boolean + /** + * Whether the pool ready event has been emitted or not. + */ + private readyEventEmitted: boolean /** * The start timestamp of the pool. */ @@ -167,6 +170,7 @@ export abstract class AbstractPool< this.started = false this.starting = false this.destroying = false + this.readyEventEmitted = false if (this.opts.startWorkers === true) { this.start() } @@ -982,6 +986,7 @@ export abstract class AbstractPool< ) this.emitter?.emit(PoolEvents.destroy, this.info) this.emitter?.emitDestroy() + this.readyEventEmitted = false this.destroying = false this.started = false } @@ -1572,12 +1577,9 @@ export abstract class AbstractPool< ) workerInfo.ready = message.ready as boolean workerInfo.taskFunctionNames = message.taskFunctionNames - if (this.ready) { - const emitPoolReadyEventOnce = once( - () => this.emitter?.emit(PoolEvents.ready, this.info), - this - ) - emitPoolReadyEventOnce() + if (!this.readyEventEmitted && this.ready) { + this.readyEventEmitted = true + this.emitter?.emit(PoolEvents.ready, this.info) } }