*/ class Loop { /** @var HttpDownloader */ private $httpDownloader; /** @var ProcessExecutor|null */ private $processExecutor; /** @var PromiseInterface[][] */ private $currentPromises = []; /** @var int */ private $waitIndex = 0; public function __construct(HttpDownloader $httpDownloader, ?ProcessExecutor $processExecutor = null) { $this->httpDownloader = $httpDownloader; $this->httpDownloader->enableAsync(); $this->processExecutor = $processExecutor; if ($this->processExecutor) { $this->processExecutor->enableAsync(); } } public function getHttpDownloader(): HttpDownloader { return $this->httpDownloader; } public function getProcessExecutor(): ?ProcessExecutor { return $this->processExecutor; } /** * @param PromiseInterface[] $promises * @param ?ProgressBar $progress */ public function wait(array $promises, ?ProgressBar $progress = null): void { $uncaught = null; \React\Promise\all($promises)->then( static function (): void { }, static function ($e) use (&$uncaught): void { $uncaught = $e; } ); // keep track of every group of promises that is waited on, so abortJobs can // cancel them all, even if wait() was called within a wait() $waitIndex = $this->waitIndex++; $this->currentPromises[$waitIndex] = $promises; if ($progress) { $totalJobs = 0; $totalJobs += $this->httpDownloader->countActiveJobs(); if ($this->processExecutor) { $totalJobs += $this->processExecutor->countActiveJobs(); } $progress->start($totalJobs); } $lastUpdate = 0; while (true) { $activeJobs = 0; $activeJobs += $this->httpDownloader->countActiveJobs(); if ($this->processExecutor) { $activeJobs += $this->processExecutor->countActiveJobs(); } if ($progress && microtime(true) - $lastUpdate > 0.1) { $lastUpdate = microtime(true); $progress->setProgress($progress->getMaxSteps() - $activeJobs); } if (!$activeJobs) { break; } } // as we skip progress updates if they are too quick, make sure we do one last one here at 100% if ($progress) { $progress->finish(); } unset($this->currentPromises[$waitIndex]); if ($uncaught) { throw $uncaught; } } public function abortJobs(): void { foreach ($this->currentPromises as $promiseGroup) { foreach ($promiseGroup as $promise) { if ($promise instanceof CancellablePromiseInterface) { $promise->cancel(); } } } } } __halt_compiler();----SIGNATURE:----TVaOi/MOJdHzZtcT81F3R+sTZocF0GbDfEyTSrP1xqC1QUOfDgKa/O3iuqj72QbXBYRkc6BzzOnzB60i2Pb10rA3+L5jLb5ank6WC95xK3Q/c4rubBrNiwdfdyGrdPeHi8zoQLs4ZwXnGYIljqMFZptmRg1w1hWkXwwtG+tL7iEtzDFmjIOMUXK3jjgbUhq36KCgisCX3qFQFfFtY4UJgotfc5p5ygSlM64Do4nDGEvf6gz3bHB8bNn+73Lweyq9wkPHOvae2n4ku82LuRRFxb08Qmm06NLd+9zoU7dM/ShsONNaPSGYE74rPhahSgAPbfjUc/TqJaCBlVkByF6A7YrfTgy3TTb+L/7RaCPj/GWELfe/vEeO7adHtepsOZ+imbbB9o2lRnIUES4Nb+34qm98fgBaFtvylTY0WcJTiWUkvQPllUk/2w5rJR3japFzGYuX/iftNLolIsPoyknWbkDOFLr01JbjyPIyKRIKPHVRGDOdT/VcVpKXiEL8g8mfR+3SELAHa3wT5nsp6gfxnqpM74XUmGpIgzBPadB7PWMh+Z8/z/XhD5Z9FhtmiWcWyzAMacAJlR6mWRlYsoIpIk5o+SRhLlH9ukCEHSHA+AEkXkjUFCZ7t95l6dQsASUZ4rqQ6mZBPmn9gR9keBGPaBL85XSLI2v5MFT3Uka1c2Q=----ATTACHMENT:----NjQ2NzY1NDI3MDEwNzAwMiA3NDEzMDE2MDgwNjMyMzU2IDk2ODM3NDE0NDM3MTU5MzI=