diff --git a/CHANGELOG b/CHANGELOG index 2f4d649..5f61fe7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +### 1.0.8 + +- Fix NativeReactor running a busy loop if no timers are active. + Properly block now in NativeReactor inside stream_select(). + ### 1.0.7 - Several combinator functions could result in a Promise already diff --git a/lib/NativeReactor.php b/lib/NativeReactor.php index 783ce1d..2d6b87b 100644 --- a/lib/NativeReactor.php +++ b/lib/NativeReactor.php @@ -195,14 +195,13 @@ class NativeReactor implements Reactor { // @TODO Instead of iterating all timers hunting for a keep-alive // we should just use a specific counter to cache the number // of keep-alive timers in use at any given time - $timeToNextAlarm = 0; + $timeToNextAlarm = null; foreach ($this->timerOrder as $watcherId => $time) { if ($this->watchers[$watcherId]->keepAlive) { // The reset() is important because the foreach modifies - // the internal array pointer. + // the internal array pointer with PHP 5. $nextTimerAt = \reset($this->timerOrder); $timeToNextAlarm = \round($nextTimerAt - \microtime(true), 4); - $timeToNextAlarm = ($timeToNextAlarm > 0) ? $timeToNextAlarm : 0; break; } } @@ -228,7 +227,10 @@ class NativeReactor implements Reactor { $w = $this->writeStreams; $e = null; - if ($timeout <= 0) { + if ($timeout === null) { + $sec = null; + $usec = null; + } elseif ($timeout <= 0) { $sec = 0; $usec = 0; } else { diff --git a/test/UvReactorTest.php b/test/UvReactorTest.php index 4cb57cc..4dc5414 100644 --- a/test/UvReactorTest.php +++ b/test/UvReactorTest.php @@ -6,7 +6,7 @@ use Amp\UvReactor; class UvReactorTest extends ReactorTest { public static function setUpBeforeClass() { - if (!defined('SIGUSR1')) { + if (!defined('SIGUSR1') && extension_loaded("uv")) { define('SIGUSR1', \Uv::SIGUSR1); } }