function terminateWorker(initializeNewWorkers = true) {
	workers.forEach((worker) => worker.terminate());
	workers.length = 0;

	if (!initializeNewWorkers) return;

	const len = navigator.hardwareConcurrency - 1 || 2;

	for (let i = 0; i < len; i++) {
		const worker = getWorker();
		worker.onmessage = onWorkerMessage;
		worker.onerror = onErrorMessage;
		workers.push(worker);
	}
}
Terminates the existing Web Workers, if any, and then initializes new ones.
Also sets the onmessage and onerror handlers for these workers.
@param {boolean} [initializeNewWorkers=true] - Whether to initialize new workers after terminating the existing ones.