mirror of
https://we.phorge.it/source/arcanist.git
synced 2025-03-12 20:34:53 +01:00
Summary: Followup to rARC99e57a70. This patch should cover all remaining issues now that PHPStan covers it (instead of the previous trial-and-error approach). Implicitly nullable parameter declarations are deprecated in PHP 8.4: https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated The proposed syntax was introduced in PHP 7.1 and Phorge requires PHP 7.2 now. Test Plan: Run static code analysis. Reviewers: O1 Blessed Committers, avivey Reviewed By: O1 Blessed Committers, avivey Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Differential Revision: https://we.phorge.it/D25831
82 lines
1.9 KiB
PHP
82 lines
1.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Wraps another @{class:Future} and allows you to post-process its result once
|
|
* it resolves.
|
|
*/
|
|
abstract class FutureProxy extends Future {
|
|
|
|
private $proxied;
|
|
|
|
public function __construct(?Future $proxied = null) {
|
|
if ($proxied) {
|
|
$this->setProxiedFuture($proxied);
|
|
}
|
|
}
|
|
|
|
public function setProxiedFuture(Future $proxied) {
|
|
$this->proxied = $proxied;
|
|
return $this;
|
|
}
|
|
|
|
protected function getProxiedFuture() {
|
|
if (!$this->proxied) {
|
|
throw new Exception(pht('The proxied future has not been provided yet.'));
|
|
}
|
|
return $this->proxied;
|
|
}
|
|
|
|
public function isReady() {
|
|
if ($this->hasResult() || $this->hasException()) {
|
|
return true;
|
|
}
|
|
|
|
$proxied = $this->getProxiedFuture();
|
|
$proxied->updateFuture();
|
|
|
|
if ($proxied->hasResult() || $proxied->hasException()) {
|
|
try {
|
|
$result = $proxied->resolve();
|
|
$result = $this->didReceiveResult($result);
|
|
} catch (Exception $ex) {
|
|
$result = $this->didReceiveException($ex);
|
|
} catch (Throwable $ex) {
|
|
$result = $this->didReceiveException($ex);
|
|
}
|
|
|
|
$this->setResult($result);
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function getReadSockets() {
|
|
return $this->getProxiedFuture()->getReadSockets();
|
|
}
|
|
|
|
public function getWriteSockets() {
|
|
return $this->getProxiedFuture()->getWriteSockets();
|
|
}
|
|
|
|
public function start() {
|
|
$this->getProxiedFuture()->start();
|
|
return $this;
|
|
}
|
|
|
|
protected function getServiceProfilerStartParameters() {
|
|
return $this->getProxiedFuture()->getServiceProfilerStartParameters();
|
|
}
|
|
|
|
protected function getServiceProfilerResultParameters() {
|
|
return $this->getProxiedFuture()->getServiceProfilerResultParameters();
|
|
}
|
|
|
|
abstract protected function didReceiveResult($result);
|
|
|
|
protected function didReceiveException($exception) {
|
|
throw $exception;
|
|
}
|
|
|
|
}
|