File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -159,7 +159,11 @@ public function run()
159
159
if ($ timeout < 0 ) {
160
160
$ timeout = 0 ;
161
161
} else {
162
- $ timeout *= self ::MICROSECONDS_PER_SECOND ;
162
+ /*
163
+ * round() needed to correct float error:
164
+ * https://github.com/reactphp/event-loop/issues/48
165
+ */
166
+ $ timeout = round ($ timeout * self ::MICROSECONDS_PER_SECOND );
163
167
}
164
168
165
169
// The only possible event is stream activity, so wait forever ...
Original file line number Diff line number Diff line change 4
4
5
5
use React \EventLoop \LoopInterface ;
6
6
use React \EventLoop \StreamSelectLoop ;
7
+ use React \EventLoop \Timer \Timer ;
7
8
8
9
class StreamSelectLoopTest extends AbstractLoopTest
9
10
{
@@ -145,4 +146,34 @@ protected function forkSendSignal($signal)
145
146
die ();
146
147
}
147
148
}
149
+
150
+ /**
151
+ * https://github.com/reactphp/event-loop/issues/48
152
+ *
153
+ * Tests that timer with very small interval uses at least 1 microsecond
154
+ * timeout.
155
+ */
156
+ public function testSmallTimerInterval ()
157
+ {
158
+ /** @var StreamSelectLoop|\PHPUnit_Framework_MockObject_MockObject $loop */
159
+ $ loop = $ this ->getMock ('React\EventLoop\StreamSelectLoop ' , ['streamSelect ' ]);
160
+ $ loop
161
+ ->expects ($ this ->at (0 ))
162
+ ->method ('streamSelect ' )
163
+ ->with ([], [], 1 );
164
+ $ loop
165
+ ->expects ($ this ->at (1 ))
166
+ ->method ('streamSelect ' )
167
+ ->with ([], [], 0 );
168
+
169
+ $ callsCount = 0 ;
170
+ $ loop ->addPeriodicTimer (Timer::MIN_INTERVAL , function () use (&$ loop , &$ callsCount ) {
171
+ $ callsCount ++;
172
+ if ($ callsCount == 2 ) {
173
+ $ loop ->stop ();
174
+ }
175
+ });
176
+
177
+ $ loop ->run ();
178
+ }
148
179
}
You can’t perform that action at this time.
0 commit comments