Skip to content

Commit b5765ff

Browse files
committed
Add StreamSelectLoop timeout rounding.
1 parent bdc6191 commit b5765ff

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/StreamSelectLoop.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ public function run()
159159
if ($timeout < 0) {
160160
$timeout = 0;
161161
} 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);
163167
}
164168

165169
// The only possible event is stream activity, so wait forever ...
@@ -230,7 +234,6 @@ protected function streamSelect(array &$read, array &$write, $timeout)
230234
{
231235
if ($read || $write) {
232236
$except = null;
233-
234237
// suppress warnings that occur, when stream_select is interrupted by a signal
235238
return @stream_select($read, $write, $except, $timeout === null ? null : 0, $timeout);
236239
}

0 commit comments

Comments
 (0)