update docs for 2.1
authorMichael Wallner <mike@php.net>
Wed, 20 May 2015 18:39:32 +0000 (20:39 +0200)
committerMichael Wallner <mike@php.net>
Wed, 20 May 2015 18:39:32 +0000 (20:39 +0200)
pq-gateway/pq/Query/AsyncExecutor.md
pq-gateway/pq/Query/AsyncExecutor/execute.md
pq-gateway/pq/Query/AsyncExecutor/setCallbacks.md [new file with mode: 0644]

index d7804d61e0f5f1d9ce33ad0158ee49f71dbc84e2..c4b8afab65d6e563bc07394c147acb5d27e73ed2 100644 (file)
@@ -3,5 +3,76 @@
 An asynchronous query executor implementation.
 See pq\Query\Executor for inherited methods and properties.
 
 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();
+       
+       ?>
index 29cbde9f327b5c71c5309be0094e70292864118f..77c6ecfdffb23f4216f6c406e671f1d925f30418 100644 (file)
@@ -2,9 +2,6 @@
 
 Execute the query asynchronously and let the callback process the result on resolve.
 
 
 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  
 ## 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 (file)
index 0000000..64a6fd5
--- /dev/null
@@ -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).