Skip to content

Commit

Permalink
fix: fix pool start timestamp handling
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
  • Loading branch information
jerome-benoit committed Apr 30, 2024
1 parent 9e3c104 commit 9213341
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/pools/abstract-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export abstract class AbstractPool<
/**
* The start timestamp of the pool.
*/
private readonly startTimestamp
private startTimestamp?: number

/**
* Constructs a new poolifier pool.
Expand Down Expand Up @@ -177,8 +177,6 @@ export abstract class AbstractPool<
if (this.opts.startWorkers === true) {
this.start()
}

this.startTimestamp = performance.now()
}

private checkPoolType(): void {
Expand Down Expand Up @@ -469,6 +467,9 @@ export abstract class AbstractPool<
* @returns The pool utilization.
*/
private get utilization(): number {
if (this.startTimestamp == null) {
return 0
}
const poolTimeCapacity = (performance.now() - this.startTimestamp) *
(this.maximumNumberOfWorkers ?? this.minimumNumberOfWorkers)
const totalTasksRunTime = this.workerNodes.reduce(
Expand Down Expand Up @@ -979,6 +980,7 @@ export abstract class AbstractPool<
}
this.starting = true
this.startMinimumNumberOfWorkers()
this.startTimestamp = performance.now()
this.starting = false
this.started = true
}
Expand All @@ -1004,6 +1006,7 @@ export abstract class AbstractPool<
new CustomEvent<PoolInfo>(PoolEvents.destroy, { detail: this.info }),
)
this.readyEventEmitted = false
delete this.startTimestamp
this.destroying = false
this.started = false
}
Expand Down

0 comments on commit 9213341

Please sign in to comment.