Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cap min timer interval at 1µs, thus improving compatibility with v0.4 #47

Merged
merged 1 commit into from
Dec 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions LibEventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class LibEventLoop implements LoopInterface
{
/** @deprecated unused, left here for BC only */
const MIN_TIMER_RESOLUTION = 0.001;

private $base;
Expand Down Expand Up @@ -150,10 +151,6 @@ public function removeStream($stream)

protected function addTimerInternal($interval, $callback, $periodic = false)
{
if ($interval < self::MIN_TIMER_RESOLUTION) {
throw new \InvalidArgumentException('Timer events do not support sub-millisecond timeouts.');
}

$timer = new Timer($this, $interval, $callback, $periodic);
$resource = event_new();

Expand All @@ -174,7 +171,7 @@ protected function addTimerInternal($interval, $callback, $periodic = false)

event_timer_set($resource, $callback);
event_base_set($resource, $this->base);
event_add($resource, $interval * 1000000);
event_add($resource, $timer->getInterval() * 1000000);

return $timer;
}
Expand Down
6 changes: 6 additions & 0 deletions Timer/Timer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

class Timer implements TimerInterface
{
const MIN_INTERVAL = 0.000001;

protected $loop;
protected $interval;
protected $callback;
Expand All @@ -19,6 +21,10 @@ public function __construct(LoopInterface $loop, $interval, $callback, $periodic
throw new InvalidArgumentException('The callback argument must be a valid callable object');
}

if ($interval < self::MIN_INTERVAL) {
$interval = self::MIN_INTERVAL;
}

$this->loop = $loop;
$this->interval = (float) $interval;
$this->callback = $callback;
Expand Down
6 changes: 1 addition & 5 deletions Timer/Timers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class Timers
{
/** @deprecated unused, left here for BC only */
const MIN_RESOLUTION = 0.001;

private $time;
Expand All @@ -33,11 +34,6 @@ public function getTime()
public function add(TimerInterface $timer)
{
$interval = $timer->getInterval();

if ($interval < self::MIN_RESOLUTION) {
throw new InvalidArgumentException('Timer events do not support sub-millisecond timeouts.');
}

$scheduledAt = $interval + $this->getTime();

$this->timers->attach($timer, $scheduledAt);
Expand Down