diff --git a/src/future/Future.php b/src/future/Future.php --- a/src/future/Future.php +++ b/src/future/Future.php @@ -63,7 +63,7 @@ $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 --- a/src/future/FutureProxy.php +++ b/src/future/FutureProxy.php @@ -27,27 +27,29 @@ } public function isReady() { - if ($this->hasResult()) { + 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); + } - $is_ready = $proxied->isReady(); - - if ($proxied->hasResult()) { - $result = $proxied->getResult(); - $result = $this->didReceiveResult($result); $this->setResult($result); - } - return $is_ready; - } + return true; + } - public function resolve() { - $this->getProxiedFuture()->resolve(); - $this->isReady(); - return $this->getResult(); + return false; } public function getReadSockets() { @@ -73,4 +75,8 @@ abstract protected function didReceiveResult($result); + protected function didReceiveException($exception) { + throw $exception; + } + }