diff --git a/LibEventLoop.php b/LibEventLoop.php index 7fb27d6d..f60c6eb2 100644 --- a/LibEventLoop.php +++ b/LibEventLoop.php @@ -8,6 +8,7 @@ class LibEventLoop implements LoopInterface { + /** @deprecated unused, left here for BC only */ const MIN_TIMER_RESOLUTION = 0.001; private $base; @@ -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(); @@ -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; } diff --git a/Timer/Timer.php b/Timer/Timer.php index 9fc72f47..9762f582 100644 --- a/Timer/Timer.php +++ b/Timer/Timer.php @@ -7,6 +7,8 @@ class Timer implements TimerInterface { + const MIN_INTERVAL = 0.000001; + protected $loop; protected $interval; protected $callback; @@ -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; diff --git a/Timer/Timers.php b/Timer/Timers.php index 520158c4..c7b9ca94 100644 --- a/Timer/Timers.php +++ b/Timer/Timers.php @@ -8,6 +8,7 @@ class Timers { + /** @deprecated unused, left here for BC only */ const MIN_RESOLUTION = 0.001; private $time; @@ -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);