diff --git a/src/future/Future.php b/src/future/Future.php index 3c371bc4..1e52c48a 100644 --- a/src/future/Future.php +++ b/src/future/Future.php @@ -63,7 +63,7 @@ abstract class Future extends Phobject { $this->hasStarted = true; $this->startServiceProfiler(); - $this->isReady(); + $this->updateFuture(); } final public function updateFuture() { diff --git a/src/future/FutureProxy.php b/src/future/FutureProxy.php index 77c8c5bb..d7e00cd6 100644 --- a/src/future/FutureProxy.php +++ b/src/future/FutureProxy.php @@ -27,27 +27,29 @@ abstract class FutureProxy extends Future { } public function isReady() { - if ($this->hasResult()) { + if ($this->hasResult() || $this->hasException()) { return true; } $proxied = $this->getProxiedFuture(); + $proxied->updateFuture(); - $is_ready = $proxied->isReady(); + 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); + } - if ($proxied->hasResult()) { - $result = $proxied->getResult(); - $result = $this->didReceiveResult($result); $this->setResult($result); + + return true; } - return $is_ready; - } - - public function resolve() { - $this->getProxiedFuture()->resolve(); - $this->isReady(); - return $this->getResult(); + return false; } public function getReadSockets() { @@ -73,4 +75,8 @@ abstract class FutureProxy extends Future { abstract protected function didReceiveResult($result); + protected function didReceiveException($exception) { + throw $exception; + } + }