mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 14:52:40 +01:00
Make "exception" on Future a private property
Summary: Depends on D21034. Ref T11968. Continue modernizing Future. Test Plan: Ran tests, created a revision. Maniphest Tasks: T11968 Differential Revision: https://secure.phabricator.com/D21035
This commit is contained in:
parent
4d55067fd8
commit
6b75562c3e
3 changed files with 90 additions and 58 deletions
|
@ -9,8 +9,7 @@ abstract class Future extends Phobject {
|
||||||
|
|
||||||
private $hasResult = false;
|
private $hasResult = false;
|
||||||
private $result;
|
private $result;
|
||||||
|
private $exception;
|
||||||
protected $exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is this future's process complete? Specifically, can this future be
|
* Is this future's process complete? Specifically, can this future be
|
||||||
|
@ -37,23 +36,34 @@ abstract class Future extends Phobject {
|
||||||
'timeout.'));
|
'timeout.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$this->hasResult()) {
|
||||||
$graph = new FutureIterator(array($this));
|
$graph = new FutureIterator(array($this));
|
||||||
$graph->resolveAll();
|
$graph->resolveAll();
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->exception) {
|
if ($this->hasException()) {
|
||||||
throw $this->exception;
|
throw $this->getException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->getResult();
|
return $this->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setException(Exception $ex) {
|
final public function updateFuture() {
|
||||||
$this->exception = $ex;
|
if ($this->hasException()) {
|
||||||
return $this;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getException() {
|
if ($this->hasResult()) {
|
||||||
return $this->exception;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->isReady();
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
$this->setException($ex);
|
||||||
|
} catch (Throwable $ex) {
|
||||||
|
$this->setException($ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,8 +135,23 @@ abstract class Future extends Phobject {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
final protected function hasResult() {
|
final public function hasResult() {
|
||||||
return $this->hasResult;
|
return $this->hasResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final private function setException($exception) {
|
||||||
|
// NOTE: The parameter may be an Exception or a Throwable.
|
||||||
|
$this->exception = $exception;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
final private function getException() {
|
||||||
|
return $this->exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
final public function hasException() {
|
||||||
|
return ($this->exception !== null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,6 +180,7 @@ final class FutureIterator extends Phobject implements Iterator {
|
||||||
$this->isTimeout = false;
|
$this->isTimeout = false;
|
||||||
|
|
||||||
$check = $this->getWorkingSet();
|
$check = $this->getWorkingSet();
|
||||||
|
|
||||||
$resolve = null;
|
$resolve = null;
|
||||||
do {
|
do {
|
||||||
$read_sockets = array();
|
$read_sockets = array();
|
||||||
|
@ -188,12 +189,17 @@ final class FutureIterator extends Phobject implements Iterator {
|
||||||
$wait_time = 1;
|
$wait_time = 1;
|
||||||
foreach ($check as $wait => $key) {
|
foreach ($check as $wait => $key) {
|
||||||
$future = $this->futures[$key];
|
$future = $this->futures[$key];
|
||||||
try {
|
|
||||||
if ($future->getException()) {
|
$future->updateFuture();
|
||||||
|
|
||||||
|
if ($future->hasException()) {
|
||||||
|
if ($resolve === null) {
|
||||||
$resolve = $wait;
|
$resolve = $wait;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ($future->isReady()) {
|
|
||||||
|
if ($future->hasResult()) {
|
||||||
if ($resolve === null) {
|
if ($resolve === null) {
|
||||||
$resolve = $wait;
|
$resolve = $wait;
|
||||||
}
|
}
|
||||||
|
@ -224,12 +230,8 @@ final class FutureIterator extends Phobject implements Iterator {
|
||||||
} else {
|
} else {
|
||||||
$wait_time = min($wait_time, $future->getDefaultWait());
|
$wait_time = min($wait_time, $future->getDefaultWait());
|
||||||
}
|
}
|
||||||
} catch (Exception $ex) {
|
|
||||||
$this->futures[$key]->setException($ex);
|
|
||||||
$resolve = $wait;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($resolve === null) {
|
if ($resolve === null) {
|
||||||
|
|
||||||
// Check for a setUpdateInterval() timeout.
|
// Check for a setUpdateInterval() timeout.
|
||||||
|
@ -253,6 +255,7 @@ final class FutureIterator extends Phobject implements Iterator {
|
||||||
|
|
||||||
$this->key = $this->wait[$resolve];
|
$this->key = $this->wait[$resolve];
|
||||||
unset($this->wait[$resolve]);
|
unset($this->wait[$resolve]);
|
||||||
|
|
||||||
$this->updateWorkingSet();
|
$this->updateWorkingSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,25 +27,29 @@ abstract class FutureProxy extends Future {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isReady() {
|
public function isReady() {
|
||||||
return $this->getProxiedFuture()->isReady();
|
if ($this->hasResult()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$proxied = $this->getProxiedFuture();
|
||||||
|
|
||||||
|
$is_ready = $proxied->isReady();
|
||||||
|
|
||||||
|
if ($proxied->hasResult()) {
|
||||||
|
$result = $proxied->getResult();
|
||||||
|
$result = $this->didReceiveResult($result);
|
||||||
|
$this->setResult($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $is_ready;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resolve() {
|
public function resolve() {
|
||||||
$result = $this->getProxiedFuture()->resolve();
|
$this->getProxiedFuture()->resolve();
|
||||||
$result = $this->didReceiveResult($result);
|
$this->isReady();
|
||||||
$this->setResult($result);
|
|
||||||
return $this->getResult();
|
return $this->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setException(Exception $ex) {
|
|
||||||
$this->getProxiedFuture()->setException($ex);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getException() {
|
|
||||||
return $this->getProxiedFuture()->getException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getReadSockets() {
|
public function getReadSockets() {
|
||||||
return $this->getProxiedFuture()->getReadSockets();
|
return $this->getProxiedFuture()->getReadSockets();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue