Skip to content

Commit 49724dc

Browse files
committed
Add 1µs minimum interval to Timer, and remove Timers::MIN_RESOLUTION.
1 parent f3a18b6 commit 49724dc

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

Timer/Timer.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22

33
namespace React\EventLoop\Timer;
44

5-
use InvalidArgumentException;
65
use React\EventLoop\LoopInterface;
76

87
class Timer implements TimerInterface
98
{
9+
const MIN_INTERVAL = 0.000001;
10+
1011
protected $loop;
1112
protected $interval;
1213
protected $callback;
1314
protected $periodic;
1415
protected $data;
1516

16-
public function __construct(LoopInterface $loop, $interval, $callback, $periodic = false, $data = null)
17+
public function __construct(LoopInterface $loop, $interval, callable $callback, $periodic = false, $data = null)
1718
{
18-
if (false === is_callable($callback)) {
19-
throw new InvalidArgumentException('The callback argument must be a valid callable object');
19+
if ($interval < self::MIN_INTERVAL) {
20+
$interval = self::MIN_INTERVAL;
2021
}
2122

2223
$this->loop = $loop;

Timer/Timers.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44

55
use SplObjectStorage;
66
use SplPriorityQueue;
7-
use InvalidArgumentException;
87

98
class Timers
109
{
11-
const MIN_RESOLUTION = 0.001;
12-
1310
private $time;
1411
private $timers;
1512
private $scheduler;
@@ -33,11 +30,6 @@ public function getTime()
3330
public function add(TimerInterface $timer)
3431
{
3532
$interval = $timer->getInterval();
36-
37-
if ($interval < self::MIN_RESOLUTION) {
38-
throw new InvalidArgumentException('Timer events do not support sub-millisecond timeouts.');
39-
}
40-
4133
$scheduledAt = $interval + $this->getTime();
4234

4335
$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