Response
>
+ /**
+ * Whether the pool is starting or not.
+ */
+ private readonly starting: boolean
/**
* The start timestamp of the pool.
*/
this.setupHook()
- while (
- this.workerNodes.reduce(
- (accumulator, workerNode) =>
- !workerNode.info.dynamic ? accumulator + 1 : accumulator,
- 0
- ) < this.numberOfWorkers
- ) {
- this.createAndSetupWorker()
- }
+ this.starting = true
+ this.startPool()
+ this.starting = false
this.startTimestamp = performance.now()
}
}
}
+ private startPool (): void {
+ while (
+ this.workerNodes.reduce(
+ (accumulator, workerNode) =>
+ !workerNode.info.dynamic ? accumulator + 1 : accumulator,
+ 0
+ ) < this.numberOfWorkers
+ ) {
+ this.createAndSetupWorker()
+ }
+ }
+
/** @inheritDoc */
public get info (): PoolInfo {
return {
}
}
- private get starting (): boolean {
- return (
- this.workerNodes.reduce(
- (accumulator, workerNode) =>
- !workerNode.info.dynamic ? accumulator + 1 : accumulator,
- 0
- ) < this.minSize
- )
- }
-
private get ready (): boolean {
return (
this.workerNodes.reduce(
const workerNodeKey = this.getWorkerNodeKey(worker)
const workerInfo = this.getWorkerInfo(workerNodeKey)
workerInfo.ready = false
- if (this.emitter != null) {
- this.emitter.emit(PoolEvents.error, error)
- }
+ this.emitter?.emit(PoolEvents.error, error)
if (this.opts.restartWorkerOnError === true && !this.starting) {
if (workerInfo.dynamic) {
this.createAndSetupDynamicWorker()
return message => {
this.checkMessageWorkerId(message)
if (message.ready != null) {
- // Worker ready message received
- this.handleWorkerReadyMessage(message)
+ // Worker ready response received
+ this.handleWorkerReadyResponse(message)
} else if (message.id != null) {
// Task execution response received
this.handleTaskExecutionResponse(message)
}
}
- private handleWorkerReadyMessage (message: MessageValue<Response>): void {
+ private handleWorkerReadyResponse (message: MessageValue<Response>): void {
const worker = this.getWorkerById(message.workerId)
this.getWorkerInfo(this.getWorkerNodeKey(worker as Worker)).ready =
message.ready as boolean
const promiseResponse = this.promiseResponseMap.get(message.id as string)
if (promiseResponse != null) {
if (message.taskError != null) {
- if (this.emitter != null) {
- this.emitter.emit(PoolEvents.taskError, message.taskError)
- }
+ this.emitter?.emit(PoolEvents.taskError, message.taskError)
promiseResponse.reject(message.taskError.message)
} else {
promiseResponse.resolve(message.data as Response)