Constructs the WorkerPool instance with a given pool size.
The number of workers in the pool (default is 4).
Finds and returns an idle worker by checking the worker status.
The index of an idle worker, or -1 if no idle workers are available.
Initializes a worker by creating it and adding an event listener for messages.
The ID of the worker to initialize.
Handles messages received from workers.
The ID of the worker sending the message.
The message received from the worker.
Terminates all workers, clears the resolve functions, and resets the pool status. This will effectively destroy the WorkerPool and free up any resources used.
Posts a message to an available worker. If no worker is available, the task is queued.
The message to send to the worker.
Any transferable objects to send with the message.
A promise that resolves when the worker finishes processing the message.
Sets the worker creator function, which is used to create new workers.
The function that creates a new worker.
Sets the limit for the number of workers in the pool.
The new pool size.
WorkerPool manages a pool of workers to efficiently handle multiple tasks in parallel. It allows for dynamic worker creation, task queuing, and managing worker utilization.
Author
Deepkolos / https://github.com/deepkolos