From e67f84aed03307cfb4c1b6584dfc56de6be1be92 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 8 Mar 2013 12:04:42 +0100 Subject: [PATCH] docs --- README.md | 49 ++++++++++++++++++++++++++++++++++++++++++++ lib/atick/Ticker.php | 3 ++- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..56d7ef4 --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +atick\Ticker +============ + +Asynchronnous resource handling, optionally (ab)using ticks + +**Example with ticks:** + +```PHP +declare(ticks=1); + +$conn = new \pq\Connection; +$conn->execAsync("SELECT * FROM foo", function ($rs) { + var_dump($rs); +}); + +$ticker = new \atick\Ticker; +$ticker->register(); +$ticker->read($conn->socket, function($fd) use ($conn) { + $conn->poll(); + if ($conn->busy) { + return false; + } + $conn->getResult(); + return true; +}); + +while (count($ticker)); +``` + +**And an example without ticks:** + +```php +$conn = new \pq\Connection; +$conn->execAsync("SELECT * FROM foo", function ($r) { + var_dump($r); +}); + +$ticker = new \atick\Ticker; +$ticker->read($conn->socket, function($fd) use ($conn) { + $conn->poll(); + if ($conn->busy) { + return false; + } + $conn->getResult(); + return true; +}); + +while($ticker()); +``` diff --git a/lib/atick/Ticker.php b/lib/atick/Ticker.php index cdc3364..1dbf4e8 100644 --- a/lib/atick/Ticker.php +++ b/lib/atick/Ticker.php @@ -121,6 +121,7 @@ class Ticker implements \Countable } /** + * Returns the count of watched fds * @implements \Countable * @return int */ @@ -141,7 +142,7 @@ class Ticker implements \Countable /** * Attach a write handler; let the callback return true, to stop watching the fd. - * @param int $fd + * @param resource $fd * @param callable $cb * @return \atick\Ticker */ -- 2.30.2