diff --git a/lib/Loop/NativeDriver.php b/lib/Loop/NativeDriver.php index a64d2c5..c6b9936 100644 --- a/lib/Loop/NativeDriver.php +++ b/lib/Loop/NativeDriver.php @@ -230,7 +230,12 @@ final class NativeDriver extends Driver return; } - if ($timeout > 0) { // Otherwise sleep with usleep() if $timeout > 0. + if ($timeout < 0) { // Only signal watchers are enabled, so sleep indefinitely. + \usleep(\PHP_INT_MAX); + return; + } + + if ($timeout > 0) { // Sleep until next timer expires. \usleep((int) ($timeout * self::MICROSEC_PER_SEC)); } } diff --git a/test/Loop/DriverTest.php b/test/Loop/DriverTest.php index 38e3b87..a6abeb0 100644 --- a/test/Loop/DriverTest.php +++ b/test/Loop/DriverTest.php @@ -360,7 +360,7 @@ abstract class DriverTest extends TestCase \call_user_func_array([$loop, $type], $args); if ($type == "onSignal") { - $loop->defer(function (): void { + $loop->delay(1, function () { \posix_kill(\getmypid(), \SIGUSR1); }); } @@ -631,11 +631,11 @@ abstract class DriverTest extends TestCase $loop->onSignal(\SIGUSR1, $fn = function ($watcherId, $signo, $i) use (&$fn, $loop, $sendSignal): void { if ($i) { $loop->onSignal(\SIGUSR1, $fn, --$i); - $loop->defer($sendSignal); + $loop->delay(1, $sendSignal); } $loop->cancel($watcherId); }, $runs); - $loop->defer($sendSignal); + $loop->delay(1, $sendSignal); $loop->run(); } }; @@ -783,7 +783,7 @@ abstract class DriverTest extends TestCase $loop->onSignal(SIGUSR1, $f(2)); $loop->defer(function () use ($loop, $sig2): void { $loop->enable($sig2); - $loop->defer(function () use ($loop): void { + $loop->delay(1, function () use ($loop) { \posix_kill(\getmypid(), \SIGUSR1); $loop->delay($msDelay = 10, function () use ($loop): void { $loop->stop();