1 # class pq\Query\AsyncExecutor extends pq\Query\Executor
3 An asynchronous query executor implementation.
4 See pq\Query\Executor for inherited methods and properties.
6 ## Example with [React/Promise](https://github.com/reactphp/promise)
10 use pq\Connection, pq\Result;
11 use pq\Query\AsyncExecutor, pq\Query\Writer;
13 use React\Promise\Deferred;
15 $conn = new Connection;
16 $exec = new AsyncExecutor($conn);
23 function(Deferred $context, $result) {
24 $context->resolve($result);
27 function(Deferred $context, callable $cb) {
28 return $context->promise()->then($cb);
32 $query = new Writer("SELECT \$1::int, \$2::int", [1, 2]);
33 $exec->execute($query, function(Result $result) {
34 var_dump($result->fetchAll());
37 # this call blocks; see pq\Connection::getResult() etc.
42 ## Example with [Amphp/Amp](https://github.com/amphp/amp)
46 use pq\Connection, pq\Result;
47 use pq\Query\AsyncExecutor, pq\Query\Writer;
51 $conn = new Connection;
52 $exec = new AsyncExecutor($conn);
59 function(Deferred $context, $result) {
60 $context->succeed($result);
63 function(Deferred $context, callable $cb) {
64 return $context->promise()->when(function($error, $result) use ($cb) {
70 $query = new Writer("SELECT \$1::int, \$2::int", [1, 2]);
71 $exec->execute($query, function(Result $result) {
72 var_dump($result->fetchAll());
75 # this call blocks; see pq\Connection::getResult() etc.