Skip to content

Commit 785b837

Browse files
authored
Merge pull request #47 from clue-labs/min-timers-for-0.3
Cap min timer interval at 1µs, thus improving compatibility with v0.4
2 parents 235cddf + 15827fd commit 785b837

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

LibEventLoop.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
class LibEventLoop implements LoopInterface
1010
{
11+
/** @deprecated unused, left here for BC only */
1112
const MIN_TIMER_RESOLUTION = 0.001;
1213

1314
private $base;
@@ -150,10 +151,6 @@ public function removeStream($stream)
150151

151152
protected function addTimerInternal($interval, $callback, $periodic = false)
152153
{
153-
if ($interval < self::MIN_TIMER_RESOLUTION) {
154-
throw new \InvalidArgumentException('Timer events do not support sub-millisecond timeouts.');
155-
}
156-
157154
$timer = new Timer($this, $interval, $callback, $periodic);
158155
$resource = event_new();
159156

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

175172
event_timer_set($resource, $callback);
176173
event_base_set($resource, $this->base);
177-
event_add($resource, $interval * 1000000);
174+
event_add($resource, $timer->getInterval() * 1000000);
178175

179176
return $timer;
180177
}

Timer/Timer.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
class Timer implements TimerInterface
99
{
10+
const MIN_INTERVAL = 0.000001;
11+
1012
protected $loop;
1113
protected $interval;
1214
protected $callback;
@@ -19,6 +21,10 @@ public function __construct(LoopInterface $loop, $interval, $callback, $periodic
1921
throw new InvalidArgumentException('The callback argument must be a valid callable object');
2022
}
2123

24+
if ($interval < self::MIN_INTERVAL) {
25+
$interval = self::MIN_INTERVAL;
26+
}
27+
2228
$this->loop = $loop;
2329
$this->interval = (float) $interval;
2430
$this->callback = $callback;

Timer/Timers.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
class Timers
1010
{
11+
/** @deprecated unused, left here for BC only */
1112
const MIN_RESOLUTION = 0.001;
1213

1314
private $time;
@@ -33,11 +34,6 @@ public function getTime()
3334
public function add(TimerInterface $timer)
3435
{
3536
$interval = $timer->getInterval();
36-
37-
if ($interval < self::MIN_RESOLUTION) {
38-
throw new InvalidArgumentException('Timer events do not support sub-millisecond timeouts.');
39-
}
40-
4137
$scheduledAt = $interval + $this->getTime();
4238

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy