From cc791f562e63b688e1102822a87fcc2e72237506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Mon, 4 Dec 2017 14:29:59 +0100 Subject: [PATCH] Remove unneeded isTimerActive() to reduce API surface --- README.md | 18 +----------------- src/ExtEventLoop.php | 9 ++------- src/ExtLibevLoop.php | 7 +------ src/ExtLibeventLoop.php | 9 ++------- src/LoopInterface.php | 21 +-------------------- src/StreamSelectLoop.php | 5 ----- tests/Timer/AbstractTimerTest.php | 13 ------------- 7 files changed, 7 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index 70ba09ce..7d7e0f38 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,6 @@ For the code of the current stable 0.4.x release, checkout the * [addTimer()](#addtimer) * [addPeriodicTimer()](#addperiodictimer) * [cancelTimer()](#canceltimer) - * [isTimerActive()](#istimeractive) * [futureTick()](#futuretick) * [addSignal()](#addsignal) * [removeSignal()](#removesignal) @@ -357,23 +356,8 @@ cancel a pending timer. See also [`addPeriodicTimer()`](#addperiodictimer) and [example #2](examples). -You can use the [`isTimerActive()`](#istimeractive) method to check if -this timer is still "active". After a timer is successfully cancelled, -it is no longer considered "active". - Calling this method on a timer instance that has not been added to this -loop instance or on a timer that is not "active" (or has already been -cancelled) has no effect. - -#### isTimerActive() - -The `isTimerActive(TimerInterface $timer): bool` method can be used to -check if a given timer is active. - -A timer is considered "active" if it has been added to this loop instance -via [`addTimer()`](#addtimer) or [`addPeriodicTimer()`](#addperiodictimer) -and has not been cancelled via [`cancelTimer()`](#canceltimer) and is not -a non-periodic timer that has already been triggered after its interval. +loop instance or on a timer that has already been cancelled has no effect. #### futureTick() diff --git a/src/ExtEventLoop.php b/src/ExtEventLoop.php index 73e7e97c..c6fc1e30 100644 --- a/src/ExtEventLoop.php +++ b/src/ExtEventLoop.php @@ -144,17 +144,12 @@ public function addPeriodicTimer($interval, callable $callback) public function cancelTimer(TimerInterface $timer) { - if ($this->isTimerActive($timer)) { + if ($this->timerEvents->contains($timer)) { $this->timerEvents[$timer]->free(); $this->timerEvents->detach($timer); } } - public function isTimerActive(TimerInterface $timer) - { - return $this->timerEvents->contains($timer); - } - public function futureTick(callable $listener) { $this->futureTickQueue->add($listener); @@ -282,7 +277,7 @@ private function createTimerCallback() $this->timerCallback = function ($_, $__, $timer) { call_user_func($timer->getCallback(), $timer); - if (!$timer->isPeriodic() && $this->isTimerActive($timer)) { + if (!$timer->isPeriodic() && $this->timerEvents->contains($timer)) { $this->cancelTimer($timer); } }; diff --git a/src/ExtLibevLoop.php b/src/ExtLibevLoop.php index 93af0cd9..8f598f6e 100644 --- a/src/ExtLibevLoop.php +++ b/src/ExtLibevLoop.php @@ -122,7 +122,7 @@ public function addTimer($interval, callable $callback) $callback = function () use ($timer) { call_user_func($timer->getCallback(), $timer); - if ($this->isTimerActive($timer)) { + if ($this->timerEvents->contains($timer)) { $this->cancelTimer($timer); } }; @@ -157,11 +157,6 @@ public function cancelTimer(TimerInterface $timer) } } - public function isTimerActive(TimerInterface $timer) - { - return $this->timerEvents->contains($timer); - } - public function futureTick(callable $listener) { $this->futureTickQueue->add($listener); diff --git a/src/ExtLibeventLoop.php b/src/ExtLibeventLoop.php index 08896b4f..fb66ecbd 100644 --- a/src/ExtLibeventLoop.php +++ b/src/ExtLibeventLoop.php @@ -163,7 +163,7 @@ public function addPeriodicTimer($interval, callable $callback) public function cancelTimer(TimerInterface $timer) { - if ($this->isTimerActive($timer)) { + if ($this->timerEvents->contains($timer)) { $event = $this->timerEvents[$timer]; event_del($event); @@ -173,11 +173,6 @@ public function cancelTimer(TimerInterface $timer) } } - public function isTimerActive(TimerInterface $timer) - { - return $this->timerEvents->contains($timer); - } - public function futureTick(callable $listener) { $this->futureTickQueue->add($listener); @@ -298,7 +293,7 @@ private function createTimerCallback() call_user_func($timer->getCallback(), $timer); // Timer already cancelled ... - if (!$this->isTimerActive($timer)) { + if (!$this->timerEvents->contains($timer)) { return; // Reschedule periodic timers ... diff --git a/src/LoopInterface.php b/src/LoopInterface.php index 6de1bd7c..5467fb61 100644 --- a/src/LoopInterface.php +++ b/src/LoopInterface.php @@ -255,13 +255,8 @@ public function addPeriodicTimer($interval, callable $callback); * * See also [`addPeriodicTimer()`](#addperiodictimer) and [example #2](examples). * - * You can use the [`isTimerActive()`](#istimeractive) method to check if - * this timer is still "active". After a timer is successfully cancelled, - * it is no longer considered "active". - * * Calling this method on a timer instance that has not been added to this - * loop instance or on a timer that is not "active" (or has already been - * cancelled) has no effect. + * loop instance or on a timer that has already been cancelled has no effect. * * @param TimerInterface $timer The timer to cancel. * @@ -269,20 +264,6 @@ public function addPeriodicTimer($interval, callable $callback); */ public function cancelTimer(TimerInterface $timer); - /** - * Check if a given timer is active. - * - * A timer is considered "active" if it has been added to this loop instance - * via [`addTimer()`](#addtimer) or [`addPeriodicTimer()`](#addperiodictimer) - * and has not been cancelled via [`cancelTimer()`](#canceltimer) and is not - * a non-periodic timer that has already been triggered after its interval. - * - * @param TimerInterface $timer The timer to check. - * - * @return boolean True if the timer is still enqueued for execution. - */ - public function isTimerActive(TimerInterface $timer); - /** * Schedule a callback to be invoked on a future tick of the event loop. * diff --git a/src/StreamSelectLoop.php b/src/StreamSelectLoop.php index e556d8b3..d40d60a8 100644 --- a/src/StreamSelectLoop.php +++ b/src/StreamSelectLoop.php @@ -152,11 +152,6 @@ public function cancelTimer(TimerInterface $timer) $this->timers->cancel($timer); } - public function isTimerActive(TimerInterface $timer) - { - return $this->timers->contains($timer); - } - public function futureTick(callable $listener) { $this->futureTickQueue->add($listener); diff --git a/tests/Timer/AbstractTimerTest.php b/tests/Timer/AbstractTimerTest.php index dc32a577..28c7a421 100644 --- a/tests/Timer/AbstractTimerTest.php +++ b/tests/Timer/AbstractTimerTest.php @@ -73,19 +73,6 @@ public function testAddPeriodicTimerCancelsItself() $this->assertSame(2, $i); } - public function testIsTimerActive() - { - $loop = $this->createLoop(); - - $timer = $loop->addPeriodicTimer(0.001, function () {}); - - $this->assertTrue($loop->isTimerActive($timer)); - - $loop->cancelTimer($timer); - - $this->assertFalse($loop->isTimerActive($timer)); - } - public function testMinimumIntervalOneMicrosecond() { $loop = $this->createLoop();