1
0
Fork 0

Simplify promise handling

pull/8444/head
Jordi Boggiano 2019-11-23 12:37:01 +01:00
parent a732ea5dd8
commit 5c62c7d566
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 9 additions and 21 deletions

View File

@ -229,29 +229,15 @@ class InstallationManager
$loop = $this->loop; $loop = $this->loop;
$io = $this->io; $io = $this->io;
$promise = new \React\Promise\Promise(function ($resolve, $reject) use ($installer, $jobType, $package, $initialPackage) { $promise = $installer->prepare($jobType, $package, $initialPackage);
$promise = $installer->prepare($jobType, $package, $initialPackage); if (null === $promise) {
if (null === $promise) { $promise = new \React\Promise\Promise(function ($resolve, $reject) { $resolve(); });
$promise = new \React\Promise\Promise(function ($resolve, $reject) { $resolve(); }); }
}
return $promise->then($resolve, $reject);
});
$promise = $promise->then(function () use ($jobType, $installManager, $repo, $operation) { $promise = $promise->then(function () use ($jobType, $installManager, $repo, $operation) {
$promise = $installManager->$jobType($repo, $operation); return $installManager->$jobType($repo, $operation);
if (null === $promise) {
$promise = new \React\Promise\Promise(function ($resolve, $reject) { $resolve(); });
}
return $promise;
})->then(function () use ($jobType, $installer, $package, $initialPackage) { })->then(function () use ($jobType, $installer, $package, $initialPackage) {
$promise = $installer->cleanup($jobType, $package, $initialPackage); return $installer->cleanup($jobType, $package, $initialPackage);
if (null === $promise) {
$promise = new \React\Promise\Promise(function ($resolve, $reject) { $resolve(); });
}
return $promise;
})->then(function () use ($jobType, $installer, $package, $initialPackage, $runScripts, $dispatcher, $installManager, $devMode, $repo, $operations, $operation) { })->then(function () use ($jobType, $installer, $package, $initialPackage, $runScripts, $dispatcher, $installManager, $devMode, $repo, $operations, $operation) {
$repo->write($devMode, $installManager); $repo->write($devMode, $installManager);
@ -263,7 +249,9 @@ class InstallationManager
$this->io->writeError(' <error>' . ucfirst($jobType) .' of '.$package->getPrettyName().' failed</error>'); $this->io->writeError(' <error>' . ucfirst($jobType) .' of '.$package->getPrettyName().' failed</error>');
$promise = $installer->cleanup($jobType, $package, $initialPackage); $promise = $installer->cleanup($jobType, $package, $initialPackage);
$loop->wait(array($promise)); if ($promise) {
$loop->wait(array($promise));
}
throw $e; throw $e;
}); });