Skip to content

Commit 6883b0d

Browse files
committed
Created timer example
1 parent 646aaa7 commit 6883b0d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

examples/timer.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php declare(strict_types=1);
2+
3+
require dirname(__DIR__) . '/vendor/autoload.php';
4+
5+
use \Chemem\Fauxton\Actions\Action;
6+
use \Clue\React\Buzz\Browser;
7+
8+
const LIMIT = 5; //arbitrary limit value
9+
10+
const TIMER = 10; //arbitrary periodic loop timer value
11+
12+
$loop = \React\EventLoop\Factory::create();
13+
14+
$since = -5; //arbitrary since parameter value
15+
16+
$action = Action::init($loop);
17+
18+
$loop->addPeriodicTimer(TIMER, function () use (&$action, &$since, &$loop) {
19+
$since += 5;
20+
$action->changes('your_database', [
21+
'descending' => 'true',
22+
'since' => $since,
23+
'limit' => LIMIT
24+
])
25+
->then(
26+
function ($result) {
27+
echo $result->getBody();
28+
},
29+
function ($error) {
30+
echo $error->getMessage();
31+
}
32+
);
33+
34+
if ($since == 25) {
35+
$loop->cancelTimer(); //cancel timer after 5 log operations
36+
}
37+
});
38+
39+
$loop->run();

0 commit comments

Comments
 (0)