)
}
- /** @inheritDoc */
- public abstract get full (): boolean
+ /**
+ * Whether the pool is full or not.
+ *
+ * The pool filling boolean status.
+ */
+ protected abstract get full (): boolean
- /** @inheritDoc */
- public abstract get busy (): boolean
+ /**
+ * Whether the pool is busy or not.
+ *
+ * The pool busyness boolean status.
+ */
+ protected abstract get busy (): boolean
protected internalBusy (): boolean {
return this.findFreeWorkerNodeKey() === -1
}
/** @inheritDoc */
- public get full (): boolean {
+ protected get full (): boolean {
return this.workerNodes.length === this.max
}
/** @inheritDoc */
- public get busy (): boolean {
+ protected get busy (): boolean {
return this.full && this.internalBusy()
}
}
}
/** @inheritDoc */
- public registerWorkerMessageListener<Message extends Data | Response>(
+ protected registerWorkerMessageListener<Message extends Data | Response>(
worker: Worker,
listener: (message: MessageValue<Message>) => void
): void {
}
/** @inheritDoc */
- public get full (): boolean {
+ protected get full (): boolean {
return this.workerNodes.length === this.numberOfWorkers
}
/** @inheritDoc */
- public get busy (): boolean {
+ protected get busy (): boolean {
return this.internalBusy()
}
}
/**
* Options for a poolifier pool.
+ *
+ * @typeParam Worker - The worker type.
*/
export interface PoolOptions<Worker extends IWorker> {
/**
* - `'busy'`: Emitted when the pool is busy.
*/
readonly emitter?: PoolEmitter
- /**
- * Whether the pool is full or not.
- *
- * The pool filling boolean status.
- */
- readonly full: boolean
- /**
- * Whether the pool is busy or not.
- *
- * The pool busyness boolean status.
- */
- readonly busy: boolean
/**
* Finds a free worker node key based on the number of tasks the worker has applied.
*
}
/** @inheritDoc */
- public get full (): boolean {
+ protected get full (): boolean {
return this.workerNodes.length === this.max
}
/** @inheritDoc */
- public get busy (): boolean {
+ protected get busy (): boolean {
return this.full && this.internalBusy()
}
}
}
/** @inheritDoc */
- public registerWorkerMessageListener<Message extends Data | Response>(
+ protected registerWorkerMessageListener<Message extends Data | Response>(
messageChannel: ThreadWorkerWithMessageChannel,
listener: (message: MessageValue<Message>) => void
): void {
}
/** @inheritDoc */
- public get full (): boolean {
+ protected get full (): boolean {
return this.workerNodes.length === this.numberOfWorkers
}
/** @inheritDoc */
- public get busy (): boolean {
+ protected get busy (): boolean {
return this.internalBusy()
}
}
/**
* Worker task interface.
+ *
+ * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
+ * @internal
*/
export interface Task<Data = unknown> {
/**
/**
* Worker node interface.
+ *
+ * @typeParam Worker - Type of worker.
+ * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
+ * @internal
*/
export interface WorkerNode<Worker extends IWorker, Data = unknown> {
+ /**
+ * Worker node worker.
+ */
worker: Worker
+ /**
+ * Worker node tasks usage statistics.
+ */
tasksUsage: TasksUsage
+ /**
+ * Worker node tasks queue.
+ */
tasksQueue: Array<Task<Data>>
}
/**
* Message object that is passed between worker and main worker.
+ *
+ * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
+ * @typeParam MainWorker - Type of main worker.
*/
export interface MessageValue<
Data = unknown,
*
* @typeParam Worker - Type of worker.
* @typeParam Response - Type of execution response. This can only be serializable data.
+ * @internal
*/
export interface PromiseResponseWrapper<
Worker extends IWorker,