X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fseekat;a=blobdiff_plain;f=lib%2FAPI%2FConsumer.php;h=3af614caa9355335c70278f36395f2f5449f8d17;hp=926eb736e756f066d61d9b7db1b497dfa0b18a4e;hb=2121556150be871684b5046af7cf250b8219128d;hpb=cac6bea94e6cde142c951566fa6387ffa54eb3cb diff --git a/lib/API/Consumer.php b/lib/API/Consumer.php index 926eb73..3af614c 100644 --- a/lib/API/Consumer.php +++ b/lib/API/Consumer.php @@ -2,15 +2,12 @@ namespace seekat\API; +use Exception; use Generator; -use http\Client; use seekat\API; -use seekat\Exception\{ - InvalidArgumentException, UnexpectedValueException, function exception -}; +use seekat\Exception\{function exception}; -final class Consumer -{ +final class Consumer { /** * Loop * @var callable @@ -79,7 +76,6 @@ final class Consumer */ function __invoke(Generator $gen) { $this->cancelled = false; - foreach ($gen as $promise) { if ($this->cancelled) { break; @@ -87,15 +83,14 @@ final class Consumer $this->give($promise, $gen); } - #($this->loop)(); - - if (!$this->cancelled) { - $this->result = $gen->getReturn(); - } - if (isset($this->result)) { - ($this->resolve)($this->result); - } else { + if ($this->cancelled) { ($this->reject)("Cancelled"); + } else { + try { + $this->result = $gen->getReturn(); + } catch (Exception $e) { + } + ($this->resolve)($this->result); } return $this->context->promise();