Skip to content

Commit 7fdef88

Browse files
committed
Remove unneeded getLoop() method and cyclic dependency with loop
Thid can easily be replaced by using closure binding as documented.
1 parent 8996c08 commit 7fdef88

File tree

7 files changed

+12
-34
lines changed

7 files changed

+12
-34
lines changed

src/ExtEventLoop.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function removeStream($stream)
112112
*/
113113
public function addTimer($interval, callable $callback)
114114
{
115-
$timer = new Timer($this, $interval, $callback, false);
115+
$timer = new Timer($interval, $callback, false);
116116

117117
$this->scheduleTimer($timer);
118118

@@ -124,7 +124,7 @@ public function addTimer($interval, callable $callback)
124124
*/
125125
public function addPeriodicTimer($interval, callable $callback)
126126
{
127-
$timer = new Timer($this, $interval, $callback, true);
127+
$timer = new Timer($interval, $callback, true);
128128

129129
$this->scheduleTimer($timer);
130130

src/LibEvLoop.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function removeStream($stream)
108108
*/
109109
public function addTimer($interval, callable $callback)
110110
{
111-
$timer = new Timer($this, $interval, $callback, false);
111+
$timer = new Timer( $interval, $callback, false);
112112

113113
$callback = function () use ($timer) {
114114
call_user_func($timer->getCallback(), $timer);
@@ -130,7 +130,7 @@ public function addTimer($interval, callable $callback)
130130
*/
131131
public function addPeriodicTimer($interval, callable $callback)
132132
{
133-
$timer = new Timer($this, $interval, $callback, true);
133+
$timer = new Timer($interval, $callback, true);
134134

135135
$callback = function () use ($timer) {
136136
call_user_func($timer->getCallback(), $timer);

src/LibEventLoop.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function removeStream($stream)
116116
*/
117117
public function addTimer($interval, callable $callback)
118118
{
119-
$timer = new Timer($this, $interval, $callback, false);
119+
$timer = new Timer($interval, $callback, false);
120120

121121
$this->scheduleTimer($timer);
122122

@@ -128,7 +128,7 @@ public function addTimer($interval, callable $callback)
128128
*/
129129
public function addPeriodicTimer($interval, callable $callback)
130130
{
131-
$timer = new Timer($this, $interval, $callback, true);
131+
$timer = new Timer($interval, $callback, true);
132132

133133
$this->scheduleTimer($timer);
134134

src/StreamSelectLoop.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function removeStream($stream)
9494
*/
9595
public function addTimer($interval, callable $callback)
9696
{
97-
$timer = new Timer($this, $interval, $callback, false);
97+
$timer = new Timer($interval, $callback, false);
9898

9999
$this->timers->add($timer);
100100

@@ -106,7 +106,7 @@ public function addTimer($interval, callable $callback)
106106
*/
107107
public function addPeriodicTimer($interval, callable $callback)
108108
{
109-
$timer = new Timer($this, $interval, $callback, true);
109+
$timer = new Timer($interval, $callback, true);
110110

111111
$this->timers->add($timer);
112112

src/Timer/Timer.php

+1-14
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,32 @@
22

33
namespace React\EventLoop\Timer;
44

5-
use React\EventLoop\LoopInterface;
6-
75
class Timer implements TimerInterface
86
{
97
const MIN_INTERVAL = 0.000001;
108

11-
protected $loop;
129
protected $interval;
1310
protected $callback;
1411
protected $periodic;
1512

1613
/**
1714
* Constructor initializes the fields of the Timer
1815
*
19-
* @param LoopInterface $loop The loop with which this timer is associated
2016
* @param float $interval The interval after which this timer will execute, in seconds
2117
* @param callable $callback The callback that will be executed when this timer elapses
2218
* @param bool $periodic Whether the time is periodic
2319
*/
24-
public function __construct(LoopInterface $loop, $interval, callable $callback, $periodic = false)
20+
public function __construct($interval, callable $callback, $periodic = false)
2521
{
2622
if ($interval < self::MIN_INTERVAL) {
2723
$interval = self::MIN_INTERVAL;
2824
}
2925

30-
$this->loop = $loop;
3126
$this->interval = (float) $interval;
3227
$this->callback = $callback;
3328
$this->periodic = (bool) $periodic;
3429
}
3530

36-
/**
37-
* {@inheritdoc}
38-
*/
39-
public function getLoop()
40-
{
41-
return $this->loop;
42-
}
43-
4431
/**
4532
* {@inheritdoc}
4633
*/

src/Timer/TimerInterface.php

-9
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,8 @@
22

33
namespace React\EventLoop\Timer;
44

5-
use React\EventLoop\LoopInterface;
6-
75
interface TimerInterface
86
{
9-
/**
10-
* Get the loop with which this timer is associated
11-
*
12-
* @return LoopInterface
13-
*/
14-
public function getLoop();
15-
167
/**
178
* Get the interval after which this timer will execute, in seconds
189
*

tests/Timer/TimersTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ public function testBlockedTimer()
1313
$loop = $this
1414
->getMockBuilder('React\EventLoop\LoopInterface')
1515
->getMock();
16-
16+
1717
$timers = new Timers();
1818
$timers->tick();
19-
19+
2020
// simulate a bunch of processing on stream events,
2121
// part of which schedules a future timer...
2222
sleep(1);
23-
$timers->add(new Timer($loop, 0.5, function () {
23+
$timers->add(new Timer(0.5, function () {
2424
$this->fail("Timer shouldn't be called");
2525
}));
2626

0 commit comments

Comments
 (0)