diff --git a/src/StreamSelectLoop.php b/src/StreamSelectLoop.php index e51a27f8..36fcac21 100644 --- a/src/StreamSelectLoop.php +++ b/src/StreamSelectLoop.php @@ -159,7 +159,29 @@ public function tick() $this->timers->tick(); - $this->waitForStreamActivity(0); + // Next-tick or future-tick queues have pending callbacks ... + if (!$this->nextTickQueue->isEmpty() || !$this->futureTickQueue->isEmpty()) { + $timeout = 0; + + // There is a pending timer, only block until it is due ... + } elseif ($scheduledAt = $this->timers->getFirst()) { + $timeout = $scheduledAt - $this->timers->getTime(); + if ($timeout < 0) { + $timeout = 0; + } else { + $timeout *= self::MICROSECONDS_PER_SECOND; + } + + // The only possible event is stream activity, so wait forever ... + } elseif ($this->readStreams || $this->writeStreams) { + $timeout = null; + + // There's nothing left to do ... + } else { + return; + } + + $this->waitForStreamActivity($timeout); } /**
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: