Skip to content

Commit

Permalink
Fix #251 - 100% CPU usage in NativeDriver
Browse files Browse the repository at this point in the history
Also use better bounds for timer - it must not execute before, but may execute a little later (on my system it were up to 7 ms actually)
  • Loading branch information
bwoebi committed Dec 11, 2018
1 parent 23b8bd2 commit 7075ef7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/Loop/NativeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private function getTimeout()
continue;
}

$expiration -= getCurrentTime();
$expiration -= $this->now();

if ($expiration < 0) {
return 0;
Expand Down
4 changes: 2 additions & 2 deletions test/Loop/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1563,8 +1563,8 @@ public function testNow()
$new = $this->loop->now();

// Allow a few milliseconds of inaccuracy.
$this->assertGreaterThanOrEqual($now - 5, $new);
$this->assertLessThanOrEqual($now + 5, $new);
$this->assertGreaterThanOrEqual($now - 1, $new);
$this->assertLessThanOrEqual($now + 10, $new);

// Same time should be returned from later call.
$this->assertSame($new, $this->loop->now());
Expand Down
4 changes: 2 additions & 2 deletions test/LoopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public function testNow()
$new = Loop::now();

// Allow a few milliseconds of inaccuracy.
$this->assertGreaterThanOrEqual($now - 5, $new);
$this->assertLessThanOrEqual($now + 5, $new);
$this->assertGreaterThanOrEqual($now - 1, $new);
$this->assertLessThanOrEqual($now + 10, $new);

// Same time should be returned from later call.
$this->assertSame($new, Loop::now());
Expand Down

0 comments on commit 7075ef7

Please sign in to comment.