1
0
mirror of https://github.com/danog/amp.git synced 2025-01-21 21:01:16 +01:00

Fix minor inconsistency Reactor::stop() called from immediately watcher

This commit is contained in:
Daniel Lowrey 2014-12-02 01:09:51 -05:00
parent dd1cbf8ca1
commit ba55ae360f
2 changed files with 12 additions and 9 deletions

View File

@ -128,15 +128,17 @@ class NativeReactor implements Reactor {
}
}
// If an immediately watcher called stop() then pull out here
if (!$this->isRunning) {
return;
}
if ($this->immediates) {
$timeToNextAlarm = 0;
} elseif ($this->alarmOrder) {
$timeToNextAlarm = $noWait ? 0 : round(min($this->alarmOrder) - microtime(true), 4);
} else {
// If an immediately watcher called stop() then isRunning === false. In such
// situations we need to complete the tick ASAP and use a timeout of zero.
// Otherwise we'll use a stream_select() timeout of one second.
$timeToNextAlarm = $noWait ? 0 : (int) $this->isRunning;
$timeToNextAlarm = $noWait ? 0 : 1;
}
if ($this->readStreams || $this->writeStreams) {

View File

@ -78,14 +78,15 @@ abstract class ReactorTest extends \PHPUnit_Framework_TestCase {
public function testUnresolvedEventsAreReenabledOnRunFollowingPreviousStop() {
$reactor = $this->getReactor();
$increment = 0;
$reactor->once(function() use (&$increment, $reactor) {
$reactor->once(function($reactor) use (&$increment) {
$increment++;
$reactor->stop();
}, $msDelay = 100);
}, $msDelay = 200);
$reactor->run(function($reactor) {
$reactor->stop();
});
$reactor->once([$reactor, 'stop'], $msDelay = 0);
$reactor->run();
$this->assertEquals(0, $increment);
usleep(150000);
$reactor->run();