import EventEmitter from 'events'
-import type { MessageValue } from '../utility-types'
import type { IWorker } from './abstract-pool'
import type { IPool } from './pool'
+/**
+ * Pool types.
+ */
+export enum PoolType {
+ FIXED = 'fixed',
+ DYNAMIC = 'dynamic'
+}
+
/**
* Internal poolifier pool emitter.
*/
*
* Events that can currently be listened to:
*
- * - `'FullPool'`
+ * - `'busy'`
*/
- readonly emitter: PoolEmitter
+ readonly emitter?: PoolEmitter
/**
- * Maximum number of workers that can be created by this pool.
+ * Pool type.
+ *
+ * If it is `'dynamic'`, it provides the `max` property.
*/
- readonly max?: number
+ readonly type: PoolType
/**
- * Whether the pool is dynamic or not.
- *
- * If it is dynamic, it provides the `max` property.
+ * Maximum number of workers that can be created by this pool.
*/
- isDynamic(): boolean
+ readonly max?: number
/**
- * Creates a new worker for this pool and sets it up completely.
+ * Whether the pool is busy or not.
*
- * @returns New, completely set up worker.
+ * The pool busyness boolean status.
*/
- createAndSetupWorker(): Worker
+ readonly busy: boolean
/**
- * Shut down given worker.
- *
- * @param worker A worker within `workers`.
+ * Number of tasks currently concurrently running.
*/
- destroyWorker(worker: Worker): void | Promise<void>
+ readonly numberOfRunningTasks: number
/**
- * Register a listener callback on a given worker.
+ * Find a tasks map entry with a free worker based on the number of tasks the worker has applied.
+ *
+ * If an entry is found with a worker that has `0` tasks, it is detected as free.
+ *
+ * If no tasks map entry with a free worker was found, `false` will be returned.
*
- * @param worker A worker.
- * @param listener A message listener callback.
+ * @returns A tasks map entry with a free worker if there was one, otherwise `false`.
*/
- registerWorkerMessageListener<Message extends Data | Response>(
- worker: Worker,
- listener: (message: MessageValue<Message>) => void
- ): void
+ findFreeTasksMapEntry(): [Worker, number] | false
}