Skip to content

Commit 7e7cc49

Browse files
committed
[EventLoop] Add a method to check the status of a timer.
1 parent f08d638 commit 7e7cc49

File tree

7 files changed

+27
-0
lines changed

7 files changed

+27
-0
lines changed

LibEvLoop.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ private function setupTimer(TimerInterface $timer)
138138
return $timer;
139139
}
140140

141+
public function isTimerActive(TimerInterface $timer)
142+
{
143+
return $this->timers->contains($timer);
144+
}
145+
141146
public function tick()
142147
{
143148
$this->loop->run(\libev\EventLoop::RUN_ONCE);

LibEventLoop.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ public function cancelTimer(TimerInterface $timer)
203203
}
204204
}
205205

206+
public function isTimerActive(TimerInterface $timer)
207+
{
208+
return $this->timers->contains($timer);
209+
}
210+
206211
public function tick()
207212
{
208213
event_base_loop($this->base, EVLOOP_ONCE | EVLOOP_NONBLOCK);

LoopInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public function removeStream($stream);
1616
public function addTimer($interval, $callback);
1717
public function addPeriodicTimer($interval, $callback);
1818
public function cancelTimer(TimerInterface $timer);
19+
public function isTimerActive(TimerInterface $timer);
1920

2021
public function tick();
2122
public function run();

StreamSelectLoop.php

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

92+
public function isTimerActive(TimerInterface $timer)
93+
{
94+
return $this->timers->contains($timer);
95+
}
96+
9297
protected function getNextEventTimeInMicroSeconds()
9398
{
9499
$nextEvent = $this->timers->getFirst();

Timer/Timer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public function isPeriodic()
5656
return $this->periodic;
5757
}
5858

59+
public function isActive()
60+
{
61+
return $this->loop->isTimerActive($this);
62+
}
63+
5964
public function cancel()
6065
{
6166
$this->loop->cancelTimer($this);

Timer/TimerInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public function getCallback();
1010
public function setData($data);
1111
public function getData();
1212
public function isPeriodic();
13+
public function isActive();
1314
public function cancel();
1415
}

Timer/Timers.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public function add(TimerInterface $timer)
4545
$this->scheduler->insert($timer, -$scheduledAt);
4646
}
4747

48+
public function contains(TimerInterface $timer)
49+
{
50+
return $this->timers->contains($timer);
51+
}
52+
4853
public function cancel(TimerInterface $timer)
4954
{
5055
$this->timers->detach($timer);

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