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