Skip to content

Commit 8996c08

Browse files
committed
Remove unneeded duplicate methods cancel() and isActive()
These can easily be replaced by Loop::cancelTimer() and Loop::isTimerActive(). This change ensures that timers are now a plain immutable data structure and offer no methods to change its state. This also prepares the timer to remove the cyclic dependency with the loop instance.
1 parent cdc8585 commit 8996c08

File tree

3 files changed

+4
-32
lines changed

3 files changed

+4
-32
lines changed

src/Timer/Timer.php

-16
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,4 @@ public function isPeriodic()
6464
{
6565
return $this->periodic;
6666
}
67-
68-
/**
69-
* {@inheritdoc}
70-
*/
71-
public function isActive()
72-
{
73-
return $this->loop->isTimerActive($this);
74-
}
75-
76-
/**
77-
* {@inheritdoc}
78-
*/
79-
public function cancel()
80-
{
81-
$this->loop->cancelTimer($this);
82-
}
8367
}

src/Timer/TimerInterface.php

-12
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,4 @@ public function getCallback();
3333
* @return bool
3434
*/
3535
public function isPeriodic();
36-
37-
/**
38-
* Determine whether the time is active
39-
*
40-
* @return bool
41-
*/
42-
public function isActive();
43-
44-
/**
45-
* Cancel this timer
46-
*/
47-
public function cancel();
4836
}

tests/Timer/AbstractTimerTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testAddPeriodicTimerWithCancel()
4343
usleep(1000);
4444
$this->tickLoop($loop);
4545

46-
$timer->cancel();
46+
$loop->cancelTimer($timer);
4747

4848
usleep(1000);
4949
$this->tickLoop($loop);
@@ -55,11 +55,11 @@ public function testAddPeriodicTimerCancelsItself()
5555

5656
$loop = $this->createLoop();
5757

58-
$loop->addPeriodicTimer(0.001, function ($timer) use (&$i) {
58+
$loop->addPeriodicTimer(0.001, function ($timer) use (&$i, $loop) {
5959
$i++;
6060

6161
if ($i == 2) {
62-
$timer->cancel();
62+
$loop->cancelTimer($timer);
6363
}
6464
});
6565

@@ -81,7 +81,7 @@ public function testIsTimerActive()
8181

8282
$this->assertTrue($loop->isTimerActive($timer));
8383

84-
$timer->cancel();
84+
$loop->cancelTimer($timer);
8585

8686
$this->assertFalse($loop->isTimerActive($timer));
8787
}

0 commit comments

Comments
 (0)