From: Michael Wallner Date: Wed, 20 May 2015 18:39:32 +0000 (+0200) Subject: update docs for 2.1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;ds=sidebyside;h=9231a1c04f14251920a42b4bfaa718d12e543722;p=mdref%2Fmdref-pq-gateway update docs for 2.1 --- diff --git a/pq-gateway/pq/Query/AsyncExecutor.md b/pq-gateway/pq/Query/AsyncExecutor.md index d7804d6..c4b8afa 100644 --- a/pq-gateway/pq/Query/AsyncExecutor.md +++ b/pq-gateway/pq/Query/AsyncExecutor.md @@ -3,5 +3,76 @@ 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) + + 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) + + 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(); + + ?> diff --git a/pq-gateway/pq/Query/AsyncExecutor/execute.md b/pq-gateway/pq/Query/AsyncExecutor/execute.md index 29cbde9..77c6ecf 100644 --- a/pq-gateway/pq/Query/AsyncExecutor/execute.md +++ b/pq-gateway/pq/Query/AsyncExecutor/execute.md @@ -2,9 +2,6 @@ Execute the query asynchronously and let the callback process the result on resolve. -> ***NOTE:*** - This asynchronous executor implementation depends on [React/Promise](https://github.com/reactphp/promise). - ## Params: * pq\Query\Writer $query diff --git a/pq-gateway/pq/Query/AsyncExecutor/setCallbacks.md b/pq-gateway/pq/Query/AsyncExecutor/setCallbacks.md new file mode 100644 index 0000000..64a6fd5 --- /dev/null +++ b/pq-gateway/pq/Query/AsyncExecutor/setCallbacks.md @@ -0,0 +1,13 @@ +# 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).