function Loop::wait
Parameters
array<PromiseInterface<mixed>> $promises:
ProgressBar|null $progress:
File
-
vendor/
composer/ composer/ src/ Composer/ Util/ Loop.php, line 58
Class
- Loop
- @author Jordi Boggiano <j.boggiano@seld.be>
Namespace
Composer\UtilCode
public function wait(array $promises, ?ProgressBar $progress = null) : void {
$uncaught = null;
\React\Promise\all($promises)->then(static function () : void {
}, static function (\Throwable $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 (null !== $uncaught) {
throw $uncaught;
}
}