![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/rector/rector/vendor/symplify/easy-parallel/src/ValueObject/ |
<?php declare (strict_types=1); namespace RectorPrefix202308\Symplify\EasyParallel\ValueObject; use RectorPrefix202308\React\Socket\TcpServer; use RectorPrefix202308\Symplify\EasyParallel\Exception\ParallelShouldNotHappenException; /** * Used from https://github.com/phpstan/phpstan-src/blob/master/src/Parallel/ProcessPool.php * * @api */ final class ProcessPool { /** * @readonly * @var \React\Socket\TcpServer */ private $tcpServer; /** * @var array<string, ParallelProcess> */ private $processes = []; public function __construct(TcpServer $tcpServer) { $this->tcpServer = $tcpServer; } public function getProcess(string $identifier) : ParallelProcess { if (!\array_key_exists($identifier, $this->processes)) { throw new ParallelShouldNotHappenException(\sprintf('Process "%s" not found.', $identifier)); } return $this->processes[$identifier]; } public function attachProcess(string $identifier, ParallelProcess $parallelProcess) : void { $this->processes[$identifier] = $parallelProcess; } public function tryQuitProcess(string $identifier) : void { if (!\array_key_exists($identifier, $this->processes)) { return; } $this->quitProcess($identifier); } public function quitProcess(string $identifier) : void { $parallelProcess = $this->getProcess($identifier); $parallelProcess->quit(); unset($this->processes[$identifier]); if ($this->processes !== []) { return; } $this->tcpServer->close(); } public function quitAll() : void { foreach (\array_keys($this->processes) as $identifier) { $this->quitProcess($identifier); } } }