3 namespace pq\Query\Executor
;
5 use \pq\Query\ExecutorInterface
;
6 use \pq\Query\WriterInterface
;
8 use \React\Promise\Deferred
;
11 * An asynchronous query executor
13 class Async
implements ExecutorInterface
18 * Create a asynchronous query exectuor
19 * @param \pq\Connection $conn
21 function __construct(\pq\Connection
$conn) {
27 * @return \pq\Connection
29 function getConnection() {
35 * @param \pq\Connection $conn
36 * @return \pq\Query\Executor\Async
38 function setConnection(\pq\Connection
$conn) {
44 * Execute the query asynchronously through \pq\Connection::execParamsAsync()
45 * @param \pq\Query\WriterInterface $query
46 * @param callable $callback
47 * @return \React\Promise\DeferredPromise
49 function execute(WriterInterface
$query, callable
$callback) {
50 $deferred = new Deferred
; // FIXME
51 $this->getConnection()->execParamsAsync($query, $query->getParams(), $query->getTypes(),
52 array($deferred->resolver(), "resolve"));
53 return $deferred->then($callback);