<?php
-namespace pq\Query\Executor;
+namespace pq\Query;
use \pq\Query\Executor;
use \pq\Query\WriterInterface;
*
* Example with amphp:
* <code>
- * use amp\Future;
- * use function amp\reactor;
+ * use Amp\Future;
+ * use function Amp\reactor;
*
* $exec = new pq\Query\AsyncExecutor(new pq\Connection);
* $exec->setCallbacks(
* },
* # then
* function(Future $context, callable $cb) {
- * return $context->when(function ($error, $result) {
+ * return $context->when(function ($error, $result) use ($cb) {
* $cb($result);
* });
* });
* @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
$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;