/** {@inheritDoc} */
public abstract get type (): PoolType
- /** {@inheritDoc} */
- public get numberOfRunningTasks (): number {
+ /**
+ * Number of tasks concurrently running.
+ */
+ private get numberOfRunningTasks (): number {
return this.promiseResponseMap.size
}
)
}
+ /** {@inheritDoc} */
+ public abstract get full (): boolean
+
/** {@inheritDoc} */
public abstract get busy (): boolean
- protected internalGetBusyStatus (): boolean {
+ protected internalBusy (): boolean {
return (
this.numberOfRunningTasks >= this.numberOfWorkers &&
this.findFreeWorkerKey() === -1
*/
public constructor (
min: number,
- protected readonly max: number,
+ private readonly max: number,
filePath: string,
opts: ClusterPoolOptions = {}
) {
}
/** {@inheritDoc} */
- public get busy (): boolean {
+ public get full (): boolean {
return this.workers.length === this.max
}
+
+ /** {@inheritDoc} */
+ public get busy (): boolean {
+ return this.full && this.findFreeWorkerKey() === -1
+ }
}
return PoolType.FIXED
}
+ /** {@inheritDoc} */
+ public get full (): boolean {
+ return this.workers.length === this.numberOfWorkers
+ }
+
/** {@inheritDoc} */
public get busy (): boolean {
- return this.internalGetBusyStatus()
+ return this.internalBusy()
}
}
Response = unknown
> extends IPool<Data, Response> {
/**
- * Pool workers item array.
+ * Pool worker type items array.
*/
readonly workers: Array<WorkerType<Worker>>
readonly type: PoolType
/**
- * Whether the pool is busy or not.
+ * Whether the pool is full or not.
*
- * The pool busyness boolean status.
+ * The pool filling boolean status.
*/
- readonly busy: boolean
+ readonly full: boolean
/**
- * Number of tasks currently concurrently running.
+ * Whether the pool is busy or not.
+ *
+ * The pool busyness boolean status.
*/
- readonly numberOfRunningTasks: number
+ readonly busy: boolean
/**
* Finds a free worker key based on the number of tasks the worker has applied.
if (this.pool.busy) {
return this.workerChoiceStrategy.choose()
}
- const freeWorkerKey = this.pool.findFreeWorkerKey()
- if (freeWorkerKey === -1) {
+ if (!this.pool.full && this.pool.findFreeWorkerKey() === -1) {
return this.createWorkerCallback()
}
return this.workerChoiceStrategy.choose()
*/
public constructor (
min: number,
- protected readonly max: number,
+ private readonly max: number,
filePath: string,
opts: PoolOptions<ThreadWorkerWithMessageChannel> = {}
) {
}
/** {@inheritDoc} */
- public get busy (): boolean {
+ public get full (): boolean {
return this.workers.length === this.max
}
+
+ /** {@inheritDoc} */
+ public get busy (): boolean {
+ return this.full && this.findFreeWorkerKey() === -1
+ }
}
return PoolType.FIXED
}
+ /** {@inheritDoc} */
+ public get full (): boolean {
+ return this.workers.length === this.numberOfWorkers
+ }
+
/** {@inheritDoc} */
public get busy (): boolean {
- return this.internalGetBusyStatus()
+ return this.internalBusy()
}
}
*/
public constructor (
type: string,
- protected isMain: boolean,
+ protected readonly isMain: boolean,
fn: (data: Data) => Response,
protected mainWorker: MainWorker | undefined | null,
opts: WorkerOptions = {
}
expect(longRunningPool.workers.length).toBe(max)
await TestUtils.waitExits(longRunningPool, max - min)
- // Here we expect the workers to be at the max size since that the task is still running
expect(longRunningPool.workers.length).toBe(min)
// We need to clean up the resources after our test
await longRunningPool.destroy()
}
expect(longRunningPool.workers.length).toBe(max)
await TestUtils.sleep(1500)
- // Here we expect the workers to be at the max size since that the task is still running
+ // Here we expect the workers to be at the max size since the task is still running
expect(longRunningPool.workers.length).toBe(max)
// We need to clean up the resources after our test
await longRunningPool.destroy()
}
expect(longRunningPool.workers.length).toBe(max)
await TestUtils.sleep(1500)
- // Here we expect the workers to be at the max size since that the task is still running
+ // Here we expect the workers to be at the max size since the task is still running
expect(longRunningPool.workers.length).toBe(max)
// We need to clean up the resources after our test
await longRunningPool.destroy()