Add try/finally to ensure we always reset the max jobs

main
Jordi Boggiano 2 years ago
parent b0665981c2
commit 96ad838686
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -311,38 +311,41 @@ class VersionGuesser
$promises = []; $promises = [];
$this->process->setMaxJobs(30); $this->process->setMaxJobs(30);
foreach ($branches as $candidate) { try {
$candidateVersion = Preg::replace('{^remotes/\S+/}', '', $candidate); foreach ($branches as $candidate) {
$candidateVersion = Preg::replace('{^remotes/\S+/}', '', $candidate);
// do not compare against itself or other feature branches
if ($candidate === $branch || $this->isFeatureBranch($packageConfig, $candidateVersion)) {
continue;
}
$cmdLine = str_replace(array('%candidate%', '%branch%'), array($candidate, $branch), $scmCmdline); // do not compare against itself or other feature branches
$promises[] = $this->process->executeAsync($cmdLine, $path)->then(function (Process $process) use (&$length, &$version, &$prettyVersion, $candidateVersion, &$promises): void { if ($candidate === $branch || $this->isFeatureBranch($packageConfig, $candidateVersion)) {
if (!$process->isSuccessful()) { continue;
return;
} }
$output = $process->getOutput(); $cmdLine = str_replace(array('%candidate%', '%branch%'), array($candidate, $branch), $scmCmdline);
if (strlen($output) < $length) { $promises[] = $this->process->executeAsync($cmdLine, $path)->then(function (Process $process) use (&$length, &$version, &$prettyVersion, $candidateVersion, &$promises): void {
$length = strlen($output); if (!$process->isSuccessful()) {
$version = $this->versionParser->normalizeBranch($candidateVersion); return;
$prettyVersion = 'dev-' . $candidateVersion; }
if ($length === 0) {
foreach ($promises as $promise) { $output = $process->getOutput();
if ($promise instanceof CancellablePromiseInterface) { if (strlen($output) < $length) {
$promise->cancel(); $length = strlen($output);
$version = $this->versionParser->normalizeBranch($candidateVersion);
$prettyVersion = 'dev-' . $candidateVersion;
if ($length === 0) {
foreach ($promises as $promise) {
if ($promise instanceof CancellablePromiseInterface) {
$promise->cancel();
}
} }
} }
} }
} });
}); }
}
$this->process->wait(); $this->process->wait();
$this->process->resetMaxJobs(); } finally {
$this->process->resetMaxJobs();
}
} }
return array('version' => $version, 'pretty_version' => $prettyVersion); return array('version' => $version, 'pretty_version' => $prettyVersion);

Loading…
Cancel
Save