Skip to content

Commit f6dbe84

Browse files
authored
Merge pull request #133 from clue-labs/active
Remove unneeded isTimerActive() to reduce API surface
2 parents d5bf858 + cc791f5 commit f6dbe84

7 files changed

+7
-75
lines changed

README.md

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ For the code of the current stable 0.4.x release, checkout the
2929
* [addTimer()](#addtimer)
3030
* [addPeriodicTimer()](#addperiodictimer)
3131
* [cancelTimer()](#canceltimer)
32-
* [isTimerActive()](#istimeractive)
3332
* [futureTick()](#futuretick)
3433
* [addSignal()](#addsignal)
3534
* [removeSignal()](#removesignal)
@@ -357,23 +356,8 @@ cancel a pending timer.
357356

358357
See also [`addPeriodicTimer()`](#addperiodictimer) and [example #2](examples).
359358

360-
You can use the [`isTimerActive()`](#istimeractive) method to check if
361-
this timer is still "active". After a timer is successfully cancelled,
362-
it is no longer considered "active".
363-
364359
Calling this method on a timer instance that has not been added to this
365-
loop instance or on a timer that is not "active" (or has already been
366-
cancelled) has no effect.
367-
368-
#### isTimerActive()
369-
370-
The `isTimerActive(TimerInterface $timer): bool` method can be used to
371-
check if a given timer is active.
372-
373-
A timer is considered "active" if it has been added to this loop instance
374-
via [`addTimer()`](#addtimer) or [`addPeriodicTimer()`](#addperiodictimer)
375-
and has not been cancelled via [`cancelTimer()`](#canceltimer) and is not
376-
a non-periodic timer that has already been triggered after its interval.
360+
loop instance or on a timer that has already been cancelled has no effect.
377361

378362
#### futureTick()
379363

src/ExtEventLoop.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,12 @@ public function addPeriodicTimer($interval, callable $callback)
144144

145145
public function cancelTimer(TimerInterface $timer)
146146
{
147-
if ($this->isTimerActive($timer)) {
147+
if ($this->timerEvents->contains($timer)) {
148148
$this->timerEvents[$timer]->free();
149149
$this->timerEvents->detach($timer);
150150
}
151151
}
152152

153-
public function isTimerActive(TimerInterface $timer)
154-
{
155-
return $this->timerEvents->contains($timer);
156-
}
157-
158153
public function futureTick(callable $listener)
159154
{
160155
$this->futureTickQueue->add($listener);
@@ -282,7 +277,7 @@ private function createTimerCallback()
282277
$this->timerCallback = function ($_, $__, $timer) {
283278
call_user_func($timer->getCallback(), $timer);
284279

285-
if (!$timer->isPeriodic() && $this->isTimerActive($timer)) {
280+
if (!$timer->isPeriodic() && $this->timerEvents->contains($timer)) {
286281
$this->cancelTimer($timer);
287282
}
288283
};

src/ExtLibevLoop.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function addTimer($interval, callable $callback)
122122
$callback = function () use ($timer) {
123123
call_user_func($timer->getCallback(), $timer);
124124

125-
if ($this->isTimerActive($timer)) {
125+
if ($this->timerEvents->contains($timer)) {
126126
$this->cancelTimer($timer);
127127
}
128128
};
@@ -157,11 +157,6 @@ public function cancelTimer(TimerInterface $timer)
157157
}
158158
}
159159

160-
public function isTimerActive(TimerInterface $timer)
161-
{
162-
return $this->timerEvents->contains($timer);
163-
}
164-
165160
public function futureTick(callable $listener)
166161
{
167162
$this->futureTickQueue->add($listener);

src/ExtLibeventLoop.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function addPeriodicTimer($interval, callable $callback)
164164

165165
public function cancelTimer(TimerInterface $timer)
166166
{
167-
if ($this->isTimerActive($timer)) {
167+
if ($this->timerEvents->contains($timer)) {
168168
$event = $this->timerEvents[$timer];
169169

170170
event_del($event);
@@ -174,11 +174,6 @@ public function cancelTimer(TimerInterface $timer)
174174
}
175175
}
176176

177-
public function isTimerActive(TimerInterface $timer)
178-
{
179-
return $this->timerEvents->contains($timer);
180-
}
181-
182177
public function futureTick(callable $listener)
183178
{
184179
$this->futureTickQueue->add($listener);
@@ -299,7 +294,7 @@ private function createTimerCallback()
299294
call_user_func($timer->getCallback(), $timer);
300295

301296
// Timer already cancelled ...
302-
if (!$this->isTimerActive($timer)) {
297+
if (!$this->timerEvents->contains($timer)) {
303298
return;
304299

305300
// Reschedule periodic timers ...

src/LoopInterface.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -255,34 +255,15 @@ public function addPeriodicTimer($interval, callable $callback);
255255
*
256256
* See also [`addPeriodicTimer()`](#addperiodictimer) and [example #2](examples).
257257
*
258-
* You can use the [`isTimerActive()`](#istimeractive) method to check if
259-
* this timer is still "active". After a timer is successfully cancelled,
260-
* it is no longer considered "active".
261-
*
262258
* Calling this method on a timer instance that has not been added to this
263-
* loop instance or on a timer that is not "active" (or has already been
264-
* cancelled) has no effect.
259+
* loop instance or on a timer that has already been cancelled has no effect.
265260
*
266261
* @param TimerInterface $timer The timer to cancel.
267262
*
268263
* @return void
269264
*/
270265
public function cancelTimer(TimerInterface $timer);
271266

272-
/**
273-
* Check if a given timer is active.
274-
*
275-
* A timer is considered "active" if it has been added to this loop instance
276-
* via [`addTimer()`](#addtimer) or [`addPeriodicTimer()`](#addperiodictimer)
277-
* and has not been cancelled via [`cancelTimer()`](#canceltimer) and is not
278-
* a non-periodic timer that has already been triggered after its interval.
279-
*
280-
* @param TimerInterface $timer The timer to check.
281-
*
282-
* @return boolean True if the timer is still enqueued for execution.
283-
*/
284-
public function isTimerActive(TimerInterface $timer);
285-
286267
/**
287268
* Schedule a callback to be invoked on a future tick of the event loop.
288269
*

src/StreamSelectLoop.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,6 @@ public function cancelTimer(TimerInterface $timer)
153153
$this->timers->cancel($timer);
154154
}
155155

156-
public function isTimerActive(TimerInterface $timer)
157-
{
158-
return $this->timers->contains($timer);
159-
}
160-
161156
public function futureTick(callable $listener)
162157
{
163158
$this->futureTickQueue->add($listener);

tests/Timer/AbstractTimerTest.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,6 @@ public function testAddPeriodicTimerCancelsItself()
7373
$this->assertSame(2, $i);
7474
}
7575

76-
public function testIsTimerActive()
77-
{
78-
$loop = $this->createLoop();
79-
80-
$timer = $loop->addPeriodicTimer(0.001, function () {});
81-
82-
$this->assertTrue($loop->isTimerActive($timer));
83-
84-
$loop->cancelTimer($timer);
85-
86-
$this->assertFalse($loop->isTimerActive($timer));
87-
}
88-
8976
public function testMinimumIntervalOneMicrosecond()
9077
{
9178
$loop = $this->createLoop();

0 commit comments

Comments
 (0)