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:
parent
dd1cbf8ca1
commit
ba55ae360f
@ -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) {
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user