- /**
- * Find a free worker based on number of tasks the worker has applied.
- *
- * If a worker was found that has `0` tasks, it is detected as free and will be returned.
- *
- * If no free worker was found, `null` will be returned.
- *
- * @param pool The pool instance.
- * @returns A free worker if there was one, otherwise `null`.
- */
- public static findFreeWorkerBasedOnTasks<
- Worker extends IWorker,
- Data,
- Response
- > (pool: IPoolInternal<Worker, Data, Response>): Worker | null {
- for (const [worker, numberOfTasks] of pool.tasks) {
- if (numberOfTasks === 0) {
- // A worker is free, use it
- return worker
- }
- }
- return null
- }
-