Skip to content

Commit c2bd6da

Browse files
committed
[EventLoop] Do not invoke callback of cancelled timers in LibEventLoop.
This bug was preventing periodic timers from being properly cancelled.
1 parent 2ac4231 commit c2bd6da

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

LibEventLoop.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,18 @@ protected function addTimerInternal($interval, $callback, $periodic = false)
173173
'callback' => $callback,
174174
'interval' => $interval * 1000000,
175175
'periodic' => $periodic,
176+
'cancelled' => false,
176177
);
177178

178179
$timer->signature = spl_object_hash($timer);
179180

180181
$callback = function () use ($timer) {
181-
call_user_func($timer->callback, $timer->signature, $timer->loop);
182+
if ($timer->cancelled === false) {
183+
call_user_func($timer->callback, $timer->signature, $timer->loop);
182184

183-
if ($timer->periodic === true) {
184-
event_add($timer->resource, $timer->interval);
185+
if ($timer->periodic === true) {
186+
event_add($timer->resource, $timer->interval);
187+
}
185188
}
186189
};
187190

@@ -207,8 +210,11 @@ public function addPeriodicTimer($interval, $callback)
207210
public function cancelTimer($signature)
208211
{
209212
if (isset($this->timers[$signature])) {
210-
event_del($resource = $this->timers[$signature]->resource);
211-
$this->timersGc[$signature] = $resource;
213+
$timer = $this->timers[$signature];
214+
215+
$timer->cancelled = true;
216+
event_del($timer->resource);
217+
$this->timersGc[$signature] = $timer->resource;
212218
unset($this->timers[$signature]);
213219
}
214220
}

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