1
0
mirror of https://github.com/danog/amp.git synced 2024-11-30 04:29:08 +01:00

Fix EventDriver warnings and bugs

Fixes #163, #159.
This commit is contained in:
Niklas Keller 2017-09-17 12:18:04 +02:00
parent 3fb7e793b8
commit 7a04dc5c21
2 changed files with 19 additions and 2 deletions

View File

@ -123,6 +123,10 @@ class EventDriver extends Driver {
foreach ($this->events as $event) {
$event->free();
}
// Unset here, otherwise $event->del() fails with a warning, because __destruct order isn't defined.
// See https://github.com/amphp/amp/issues/159.
$this->events = [];
}
/**
@ -176,6 +180,7 @@ class EventDriver extends Driver {
*/
protected function dispatch(bool $blocking) {
$this->handle->loop($blocking ? \EventBase::LOOP_ONCE : \EventBase::LOOP_ONCE | \EventBase::LOOP_NONBLOCK);
$this->now = (int) (\microtime(true) * self::MILLISEC_PER_SEC);
}
/**
@ -251,8 +256,6 @@ class EventDriver extends Driver {
break;
}
}
$this->now = $now;
}
/**

View File

@ -3,6 +3,7 @@
namespace Amp\Test\Loop;
use Amp\Coroutine;
use Amp\Delayed;
use Amp\Failure;
use Amp\Loop;
use Amp\Loop\Driver;
@ -1483,4 +1484,17 @@ abstract class DriverTest extends TestCase {
$this->assertLessThan(2, \abs($j - $k));
$this->assertNotSame(0, $j);
}
public function testBug163ConsecutiveDelayed() {
$emits = 3;
Loop::run(function () use (&$time, $emits) {
$time = microtime(true);
for ($i = 0; $i < $emits; ++$i) {
yield new Delayed(100);
}
$time = microtime(true) - $time;
});
$this->assertGreaterThan(100 * $emits - 1 /* 1ms grace period */, $time * 1000);
}
}