- /**
- * 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 workerTasksMap The pool worker tasks map.
- * @returns A free worker if there was one, otherwise `null`.
- */
- public static findFreeWorkerBasedOnTasks<Worker extends IWorker> (
- workerTasksMap: Map<Worker, number>
- ): Worker | null {
- for (const [worker, numberOfTasks] of workerTasksMap) {
- if (numberOfTasks === 0) {
- // A worker is free, use it
- return worker
- }
- }
- return null
- }
-