From 742512a5c86cfe8e1a0a22c4c57e8fd18b556012 Mon Sep 17 00:00:00 2001 From: Jur Balledux Date: Fri, 27 May 2016 10:02:36 +0200 Subject: [PATCH] If tick is called, wait for next like the run() loop does --- src/StreamSelectLoop.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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); } /** 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