From: Michael Wallner Date: Fri, 20 Feb 2015 19:28:21 +0000 (+0100) Subject: flush X-Git-Tag: v2.1.0~1^2~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=5acefb4aa883da15d9d1250e680b7fef8f25889a;p=m6w6%2Fpq-gateway flush --- diff --git a/lib/pq/Query/AsyncExecutor.php b/lib/pq/Query/AsyncExecutor.php index e7c1c35..a309ce6 100644 --- a/lib/pq/Query/AsyncExecutor.php +++ b/lib/pq/Query/AsyncExecutor.php @@ -1,6 +1,6 @@ - * use amp\Future; - * use function amp\reactor; + * use Amp\Future; + * use function Amp\reactor; * * $exec = new pq\Query\AsyncExecutor(new pq\Connection); * $exec->setCallbacks( @@ -69,7 +69,7 @@ class AsyncExecutor extends Executor * }, * # then * function(Future $context, callable $cb) { - * return $context->when(function ($error, $result) { + * return $context->when(function ($error, $result) use ($cb) { * $cb($result); * }); * }); @@ -99,29 +99,19 @@ class AsyncExecutor extends Executor * @param callable $callback * @return array($context, $resolver) */ - protected function prepareCallback(callable $callback/*, ... */) { + protected function prepareCallbacks(callable $callback/*, ... */) { list($init, $done, $then) = $this->getCallbacks(); $context = $init(); foreach (func_get_args() as $cb) { $then($context, $cb); } - $then($context, $callback); return array($context, function($result) use ($context, $done) { $done($context, $result); }); } - /** - * Result callback - * @param \pq\Result $result - */ - protected function receiveResult(\pq\Result $result) { - $this->result = $result; - $this->notify(); - } - /** * Execute the query asynchronously through \pq\Connection::execParamsAsync() * @param \pq\Query\WriterInterface $query @@ -133,8 +123,11 @@ class AsyncExecutor extends Executor $this->query = $query; $this->notify(); - list($context, $resolver) = $this->prepareCallback( - array($this, "receiveResult"), $callback); + list($context, $resolver) = $this->prepareCallbacks( + function(\pq\Result $result) { + $this->result = $result; + $this->notify(); + }, $callback); $this->getConnection()->execParamsAsync($query, $query->getParams(), $query->getTypes(), $resolver); return $context;