simplify generator invoker
authorMichael Wallner <mike@php.net>
Tue, 17 May 2016 07:45:54 +0000 (09:45 +0200)
committerMichael Wallner <mike@php.net>
Tue, 17 May 2016 07:45:54 +0000 (09:45 +0200)
lib/API/Invoker.php

index ff3a91e04a7fc7c7d977cc3e78a886e161f020ff..e52eedc7a3ec48421779b1427e28f734172bada5 100644 (file)
@@ -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);
                                }
                        });
                }