Skip to content

Commit 066ada7

Browse files
committed
Updated LibUvLoop to match the latest changes in reactphp/event-loop:master
1 parent b98c8a4 commit 066ada7

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

src/LibUvLoop.php

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use React\EventLoop\Tick\FutureTickQueue;
66
use React\EventLoop\Timer\Timer;
7-
use React\EventLoop\Timer\TimerInterface;
87
use SplObjectStorage;
98

109
/**
@@ -15,12 +14,12 @@ class LibUvLoop implements LoopInterface
1514
private $uv;
1615
private $futureTickQueue;
1716
private $timerEvents;
18-
private $events = [];
19-
private $flags = [];
20-
private $listeners = [];
17+
private $events = array();
18+
private $flags = array();
19+
private $listeners = array();
2120
private $running;
2221
private $signals;
23-
private $signalEvents = [];
22+
private $signalEvents = array();
2423
private $streamListener;
2524

2625
public function __construct()
@@ -30,27 +29,13 @@ public function __construct()
3029
$this->timerEvents = new SplObjectStorage();
3130
$this->streamListener = $this->createStreamListener();
3231

33-
$this->signals = new SignalsHandler(
34-
$this,
35-
function ($signal) {
36-
$this->signalEvents[$signal] = \uv_signal_init($this->uv);
37-
\uv_signal_start($this->signalEvents[$signal], function () use ($signal) {
38-
$this->signals->call($signal);
39-
}, $signal);
40-
},
41-
function ($signal) {
42-
if ($this->signals->count($signal) === 0) {
43-
\uv_signal_stop($this->signalEvents[$signal]);
44-
unset($this->signalEvents[$signal]);
45-
}
46-
}
47-
);
32+
$this->signals = new SignalsHandler();
4833
}
4934

5035
/**
5136
* {@inheritdoc}
5237
*/
53-
public function addReadStream($stream, callable $listener)
38+
public function addReadStream($stream, $listener)
5439
{
5540
if (isset($this->listeners[(int) $stream]['read'])) {
5641
return;
@@ -63,7 +48,7 @@ public function addReadStream($stream, callable $listener)
6348
/**
6449
* {@inheritdoc}
6550
*/
66-
public function addWriteStream($stream, callable $listener)
51+
public function addWriteStream($stream, $listener)
6752
{
6853
if (isset($this->listeners[(int) $stream]['write'])) {
6954
return;
@@ -104,7 +89,7 @@ public function removeWriteStream($stream)
10489
/**
10590
* {@inheritdoc}
10691
*/
107-
public function addTimer($interval, callable $callback)
92+
public function addTimer($interval, $callback)
10893
{
10994
$timer = new Timer( $interval, $callback, false);
11095

@@ -120,7 +105,7 @@ public function addTimer($interval, callable $callback)
120105
$this->timerEvents->attach($timer, $event);
121106
\uv_timer_start(
122107
$event,
123-
$interval * 1000,
108+
(int)($interval * 1000),
124109
0,
125110
$callback
126111
);
@@ -131,7 +116,7 @@ public function addTimer($interval, callable $callback)
131116
/**
132117
* {@inheritdoc}
133118
*/
134-
public function addPeriodicTimer($interval, callable $callback)
119+
public function addPeriodicTimer($interval, $callback)
135120
{
136121
$timer = new Timer($interval, $callback, true);
137122

@@ -173,19 +158,32 @@ public function isTimerActive(TimerInterface $timer)
173158
/**
174159
* {@inheritdoc}
175160
*/
176-
public function futureTick(callable $listener)
161+
public function futureTick($listener)
177162
{
178163
$this->futureTickQueue->add($listener);
179164
}
180165

181-
public function addSignal($signal, callable $listener)
166+
public function addSignal($signal, $listener)
182167
{
183168
$this->signals->add($signal, $listener);
169+
170+
if (!isset($this->signalEvents[$signal])) {
171+
$signals = $this->signals;
172+
$this->signalEvents[$signal] = \uv_signal_init($this->uv);
173+
\uv_signal_start($this->signalEvents[$signal], function () use ($signals, $signal) {
174+
$signals->call($signal);
175+
}, $signal);
176+
}
184177
}
185178

186-
public function removeSignal($signal, callable $listener)
179+
public function removeSignal($signal, $listener)
187180
{
188181
$this->signals->remove($signal, $listener);
182+
183+
if (isset($this->signalEvents[$signal]) && $this->signals->count($signal) === 0) {
184+
\uv_signal_stop($this->signalEvents[$signal]);
185+
unset($this->signalEvents[$signal]);
186+
}
189187
}
190188

191189
/**

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