diff --git a/src/StreamSelectLoop.php b/src/StreamSelectLoop.php index e51a27f8..696b05ef 100644 --- a/src/StreamSelectLoop.php +++ b/src/StreamSelectLoop.php @@ -186,7 +186,11 @@ public function run() if ($timeout < 0) { $timeout = 0; } else { - $timeout *= self::MICROSECONDS_PER_SECOND; + /* + * round() needed to correct float error: + * https://github.com/reactphp/event-loop/issues/48 + */ + $timeout = round($timeout * self::MICROSECONDS_PER_SECOND); } // The only possible event is stream activity, so wait forever ... diff --git a/tests/StreamSelectLoopTest.php b/tests/StreamSelectLoopTest.php index 5cb957b7..d2e3e078 100644 --- a/tests/StreamSelectLoopTest.php +++ b/tests/StreamSelectLoopTest.php @@ -4,6 +4,7 @@ use React\EventLoop\LoopInterface; use React\EventLoop\StreamSelectLoop; +use React\EventLoop\Timer\Timer; class StreamSelectLoopTest extends AbstractLoopTest { @@ -145,4 +146,34 @@ protected function forkSendSignal($signal) die(); } } + + /** + * https://github.com/reactphp/event-loop/issues/48 + * + * Tests that timer with very small interval uses at least 1 microsecond + * timeout. + */ + public function testSmallTimerInterval() + { + /** @var StreamSelectLoop|\PHPUnit_Framework_MockObject_MockObject $loop */ + $loop = $this->getMock('React\EventLoop\StreamSelectLoop', ['streamSelect']); + $loop + ->expects($this->at(0)) + ->method('streamSelect') + ->with([], [], 1); + $loop + ->expects($this->at(1)) + ->method('streamSelect') + ->with([], [], 0); + + $callsCount = 0; + $loop->addPeriodicTimer(Timer::MIN_INTERVAL, function() use (&$loop, &$callsCount) { + $callsCount++; + if ($callsCount == 2) { + $loop->stop(); + } + }); + + $loop->run(); + } } 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