Skip to content

Commit b56ce2e

Browse files
author
Aaron Stephens
committed
[EventLoop] Changed StreamSelectLoop to use non-blocking behavior on tick()
1 parent 798a43b commit b56ce2e

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

StreamSelectLoop.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,23 @@ protected function sleepOnPendingTimers()
122122
}
123123
}
124124

125-
protected function runStreamSelect()
125+
protected function runStreamSelect($block)
126126
{
127127
$read = $this->readStreams ?: null;
128128
$write = $this->writeStreams ?: null;
129129
$except = null;
130130

131131
if (!$read && !$write) {
132-
$this->sleepOnPendingTimers();
132+
if ($block) {
133+
$this->sleepOnPendingTimers();
134+
}
133135

134136
return;
135137
}
136138

137-
if (stream_select($read, $write, $except, 0, $this->getNextEventTimeInMicroSeconds()) > 0) {
139+
$timeout = $block ? $this->getNextEventTimeInMicroSeconds() : 0;
140+
141+
if (stream_select($read, $write, $except, 0, $timeout) > 0) {
138142
if ($read) {
139143
foreach ($read as $stream) {
140144
$listener = $this->readListeners[(int) $stream];
@@ -155,21 +159,23 @@ protected function runStreamSelect()
155159
}
156160
}
157161

158-
public function tick()
162+
protected function loop($block = true)
159163
{
160164
$this->timers->tick();
161-
$this->runStreamSelect();
165+
$this->runStreamSelect($block);
162166

163167
return $this->running;
164168
}
165169

170+
public function tick()
171+
{
172+
return $this->loop(false);
173+
}
174+
166175
public function run()
167176
{
168177
$this->running = true;
169-
170-
while ($this->tick()) {
171-
// NOOP
172-
}
178+
while ($this->loop());
173179
}
174180

175181
public function stop()

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