8000 Avoid cyclic callback references · reactphp/event-loop@f261f47 · GitHub
[go: up one dir, main page]

Skip to content

Commit f261f47

Browse files
committed
Avoid cyclic callback references
1 parent 3e4421b commit f261f47

File tree

4 files changed

+4
-30
lines changed

4 files changed

+4
-30
lines changed

src/ExtEventLoop.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,7 @@ public function addSignal($signal, $listener)
149149
$this->signals->add($signal, $listener);
150150

151151
if (!isset($this->signalEvents[$signal])) {
152-
$this->signalEvents[$signal] = Event::signal($this->eventBase, $signal, $f = function () use ($signal, &$f) {
153-
$this->signals->call($signal);
154-
// Ensure there are two copies of the callable around until it has been executed.
155-
// For more information see: https://bugs.php.net/bug.php?id=62452
156-
// Only an issue for PHP 5, this hack can be removed once PHP 5 support has been dropped.
157-
$g = $f;
158-
$f = $g;
159-
});
152+
$this->signalEvents[$signal] = Event::signal($this->eventBase, $signal, array($this->signals, 'call'));
160153
$this->signalEvents[$signal]->add();
161154
}
162155
}

src/ExtLibevLoop.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,8 @@ public function addSignal($signal, $listener)
148148
$this->signals->add($signal, $listener);
149149

150150
if (!isset($this->signalEvents[$signal])) {
151-
$this->signalEvents[$signal] = new SignalEvent($f = function () use ( 8000 $signal, &$f) {
151+
$this->signalEvents[$signal] = new SignalEvent(function () use ($signal) {
152152
$this->signals->call($signal);
153-
// Ensure there are two copies of the callable around until it has been executed.
154-
// For more information see: https://bugs.php.net/bug.php?id=62452
155-
// Only an issue for PHP 5, this hack can be removed once PHP 5 support has been dropped.
156-
$g = $f;
157-
$f = $g;
158153
}, $signal);
159154
$this->loop->add($this->signalEvents[$signal]);
160155
}

src/ExtLibeventLoop.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,7 @@ public function addSignal($signal, $listener)
165165

166166
if (!isset($this->signalEvents[$signal])) {
167167
$this->signalEvents[$signal] = event_new();
168-
event_set($this->signalEvents[$signal], $signal, EV_PERSIST | EV_SIGNAL, $f = function () use ($signal, &$f) {
169-
$this->signals->call($signal);
170-
// Ensure there are two copies of the callable around until it has been executed.
171-
// For more information see: https://bugs.php.net/bug.php?id=62452
172-
// Only an issue for PHP 5, this hack can be removed once PHP 5 support has been dropped.
173-
$g = $f;
174-
$f = $g;
175-
});
168+
event_set($this->signalEvents[$signal], $signal, EV_PERSIST | EV_SIGNAL, array($this->signals, 'call'));
176169
event_base_set($this->signalEvents[$signal], $this->eventBase);
177170
event_add($this->signalEvents[$signal]);
178171
}

src/StreamSelectLoop.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,7 @@ public function addSignal($signal, $listener)
150150
$this->signals->add($signal, $listener);
151151

152152
if ($first) {
153-
\pcntl_signal($signal, $f = function ($signal) use (&$f) {
154-
$this->signals->call($signal);
155-
// Ensure there are two copies of the callable around until it has been executed.
156-
// For more information see: https://bugs.php.net/bug.php?id=62452
157-
// Only an issue for PHP 5, this hack can be removed once PHP 5 support has been dropped.
158-
$g = $f;
159-
$f = $g;
160-
});
153+
\pcntl_signal($signal, array($this->signals, 'call'));
161154
}
162155
}
163156

0 commit comments

Comments
 (0)
0