Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/React/EventLoop/StreamSelectLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,23 @@ protected function sleepOnPendingTimers()
}
}

protected function runStreamSelect()
protected function runStreamSelect($block)
{
$read = $this->readStreams ?: null;
$write = $this->writeStreams ?: null;
$except = null;

if (!$read && !$write) {
$this->sleepOnPendingTimers();
if ($block) {
$this->sleepOnPendingTimers();
}

return;
}

if (stream_select($read, $write, $except, 0, $this->getNextEventTimeInMicroSeconds()) > 0) {
$timeout = $block ? $this->getNextEventTimeInMicroSeconds() : 0;

if (stream_select($read, $write, $except, 0, $timeout) > 0) {
if ($read) {
foreach ($read as $stream) {
$listener = $this->readListeners[(int) $stream];
Expand All @@ -155,21 +159,23 @@ protected function runStreamSelect()
}
}

public function tick()
protected function loop($block = true)
{
$this->timers->tick();
$this->runStreamSelect();
$this->runStreamSelect($block);

return $this->running;
}

public function tick()
{
return $this->loop(false);
}

public function run()
{
$this->running = true;

while ($this->tick()) {
// NOOP
}
while ($this->loop());
}

public function stop()
Expand Down