reactphp/react — pull request #128 by nrk (2013-01-12 18:46:23+00:00)
Title: [EventLoop] Rewrite the whole public abstraction for timers.

This PR ships with some __breaking changes__ in the public API needed to provide a much nicer public abstraction for timers, with the added bonus of a more polished internal implementation of timers for all of our currently supported event loops.

We now have instances of `React\EventLoop\Timer\Timer` (which is common to all the event loop implementations) being returned to user code instead of ugly strings used as timer identifiers. This gives us a much greater flexibility as illustrated by the following snippet:

```php
$timer = $loop->addPeriodicTimer(0.5, function ($timer) {
$data = $timer->getData() ?: 1;
echo "TICK: $data\n";

if ($data === 3) {
$timer->cancel();
} else {
$timer->setData(++$data);
}
});

echo "Is timer active: ", $timer->isActive() ? 'YES' : 'NO', "\n";
$loop->run();
echo "Is timer active: ", $timer->isActive() ? 'YES' : 'NO', "\n";
```

which produces the following output:

```
Is timer active: YES
TICK: 1
TICK: 2
TICK: 3
Is timer active: NO
```