From: Michael Wallner Date: Tue, 17 May 2016 07:45:54 +0000 (+0200) Subject: simplify generator invoker X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=0bb8fbef656d708ffbc7a4c331f023b118e8e331;p=m6w6%2Fseekat simplify generator invoker --- diff --git a/lib/API/Invoker.php b/lib/API/Invoker.php index ff3a91e..e52eedc 100644 --- a/lib/API/Invoker.php +++ b/lib/API/Invoker.php @@ -66,7 +66,7 @@ class Invoker extends Deferred if ($this->cancelled) { break; } - $this->queue($promise, $gen); + $this->give($promise, $gen); } if (!$this->cancelled) { @@ -87,24 +87,20 @@ class Invoker extends Deferred /** * Promise handler * - * @param \React\Promise\PromiseInterface $promise - * @param \Generator $to + * @param array|\React\Promise\PromiseInterface $promise + * @param \Generator $gen */ - private function give(PromiseInterface $promise, Generator $to) { - $promise->then(function($result) use($to) { - if (($promise = $to->send($result))) { - $this->queue($promise, $to); - } - }); - } - - private function queue($promise, Generator $gen) { + private function give($promise, Generator $gen) { if ($promise instanceof PromiseInterface) { - $this->give($promise, $gen); + $promise->then(function($result) use($gen) { + if (($promise = $gen->send($result))) { + $this->give($promise, $gen); + } + }); } else { all($promise)->then(function($results) use($gen) { if (($promise = $gen->send($results))) { - $this->queue($promise, $gen); + $this->give($promise, $gen); } }); }