An asynchronous query executor implementation.
See pq\Query\Executor for inherited methods and properties.
-> ***NOTE:***
- This asynchronous executor implementation depends on [React/Promise](https://github.com/reactphp/promise).
+## Example with [React/Promise](https://github.com/reactphp/promise)
+
+ <?php
+
+ use pq\Connection, pq\Result;
+ use pq\Query\AsyncExecutor, pq\Query\Writer;
+
+ use React\Promise\Deferred;
+
+ $conn = new Connection;
+ $exec = new AsyncExecutor($conn);
+ $exec->setCallbacks(
+ # init context
+ function() {
+ return new Deferred;
+ },
+ # done
+ function(Deferred $context, $result) {
+ $context->resolve($result);
+ },
+ # then
+ function(Deferred $context, callable $cb) {
+ return $context->promise()->then($cb);
+ });
+
+ # a contrived query
+ $query = new Writer("SELECT \$1::int, \$2::int", [1, 2]);
+ $exec->execute($query, function(Result $result) {
+ var_dump($result->fetchAll());
+ });
+
+ # this call blocks; see pq\Connection::getResult() etc.
+ $conn->getResult();
+
+ ?>
+
+## Example with [Amphp/Amp](https://github.com/amphp/amp)
+
+ <?php
+
+ use pq\Connection, pq\Result;
+ use pq\Query\AsyncExecutor, pq\Query\Writer;
+
+ use Amphp\Deferred;
+
+ $conn = new Connection;
+ $exec = new AsyncExecutor($conn);
+ $exec->setCallbacks(
+ # init context
+ function() {
+ return new Deferred;
+ },
+ # done
+ function(Deferred $context, $result) {
+ $context->succeed($result);
+ },
+ # then
+ function(Deferred $context, callable $cb) {
+ return $context->promise()->when(function($error, $result) use ($cb) {
+ $cb($result);
+ });
+ });
+
+ # a contrived query
+ $query = new Writer("SELECT \$1::int, \$2::int", [1, 2]);
+ $exec->execute($query, function(Result $result) {
+ var_dump($result->fetchAll());
+ });
+
+ # this call blocks; see pq\Connection::getResult() etc.
+ $conn->getResult();
+
+ ?>
--- /dev/null
+# void pq\Query\AsyncExecutor::setCallbacks(callable $init, callable $done, callable $then)
+
+Set the callbacks the asynchronous executor should use to resolve the result.
+See pq\Query\AsyncExecutor for examples.
+
+## Params:
+
+* callable $init
+ Initialize a context for the other callbacks, as function().
+* callable $done
+ Result resolver, as function($context, pq\Result $result).
+* callable $then
+ Callback forwarder, as function($context, callable $cb).