max,
median,
min,
- once,
round
} from '../utils'
import { KillBehaviors } from '../worker/worker-options'
* 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.
*/
this.started = false
this.starting = false
this.destroying = false
+ this.readyEventEmitted = false
if (this.opts.startWorkers === true) {
this.start()
}
)
this.emitter?.emit(PoolEvents.destroy, this.info)
this.emitter?.emitDestroy()
+ this.readyEventEmitted = false
this.destroying = false
this.started = false
}
)
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)
}
}