mirror of
https://github.com/danog/amp.git
synced 2025-01-22 05:11:42 +01:00
Don't unload watchers when the run loop finishes
This commit is contained in:
parent
a7b057ace1
commit
e209ee189d
@ -111,13 +111,6 @@ class EvReactor implements Reactor {
|
||||
$this->loop->run($flags);
|
||||
}
|
||||
|
||||
if ($this->watchers) {
|
||||
foreach (\array_keys($this->watchers) as $watcherId) {
|
||||
$watcher = $this->watchers[$watcherId];
|
||||
$this->cancel($watcherId);
|
||||
}
|
||||
}
|
||||
|
||||
$this->state = self::STOPPED;
|
||||
if ($this->stopException) {
|
||||
$e = $this->stopException;
|
||||
|
@ -92,12 +92,6 @@ class LibeventReactor implements Reactor {
|
||||
\event_base_loop($this->keepAliveBase, $flags);
|
||||
}
|
||||
|
||||
if ($this->watchers) {
|
||||
foreach (\array_keys($this->watchers) as $watcherId) {
|
||||
$this->cancel($watcherId);
|
||||
}
|
||||
}
|
||||
|
||||
$this->state = self::STOPPED;
|
||||
if ($this->stopException) {
|
||||
$e = $this->stopException;
|
||||
|
@ -58,7 +58,6 @@ class NativeReactor implements Reactor {
|
||||
$this->state = self::STARTING;
|
||||
$watcherId = $this->immediately($onStart);
|
||||
if (!$this->tryImmediate($this->watchers[$watcherId]) || empty($this->keepAliveCount)) {
|
||||
$this->unload();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@ -74,7 +73,8 @@ class NativeReactor implements Reactor {
|
||||
}
|
||||
}
|
||||
|
||||
$this->unload();
|
||||
$this->timersEnabled = false;
|
||||
$this->state = self::STOPPED;
|
||||
}
|
||||
|
||||
private function unload() {
|
||||
@ -153,10 +153,8 @@ class NativeReactor implements Reactor {
|
||||
$this->doTick((bool) $noWait);
|
||||
$this->state = self::STOPPED;
|
||||
} catch (\Throwable $e) {
|
||||
$this->unload();
|
||||
throw $e;
|
||||
} catch (\Exception $e) {
|
||||
$this->unload();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
@ -93,12 +93,6 @@ class UvReactor implements Reactor {
|
||||
\uv_run($this->loop, \UV::RUN_DEFAULT | (empty($this->immediates) ? \UV::RUN_ONCE : \UV::RUN_NOWAIT));
|
||||
}
|
||||
|
||||
if ($this->watchers) {
|
||||
foreach (\array_keys($this->watchers) as $watcherId) {
|
||||
$this->cancel($watcherId);
|
||||
}
|
||||
}
|
||||
|
||||
$this->state = self::STOPPED;
|
||||
if ($this->stopException) {
|
||||
$e = $this->stopException;
|
||||
|
@ -291,36 +291,34 @@ abstract class ReactorTest extends BaseTest {
|
||||
});
|
||||
}
|
||||
|
||||
public function testThatWatchersAreCollectedWhenRunLoopExits() {
|
||||
public function testEnablingWatcherAllowsSubsequentInvocation() {
|
||||
$increment = 0;
|
||||
$watcherId = \Amp\immediately(function () use (&$increment) {
|
||||
$increment++;
|
||||
});
|
||||
\Amp\disable($watcherId);
|
||||
|
||||
$watcherId = \Amp\once(function () use (&$increment) {
|
||||
$increment++;
|
||||
}, 1);
|
||||
\Amp\disable($watcherId);
|
||||
|
||||
$watcherId = \Amp\repeat(function () use (&$increment) {
|
||||
$increment++;
|
||||
}, 1);
|
||||
\Amp\disable($watcherId);
|
||||
|
||||
$watcherId = \Amp\onReadable(STDIN, function () use (&$increment) {
|
||||
$increment++;
|
||||
});
|
||||
\Amp\disable($watcherId);
|
||||
|
||||
$watcherId = \Amp\onWritable(STDOUT, function () use (&$increment) {
|
||||
$increment++;
|
||||
});
|
||||
\Amp\disable($watcherId);
|
||||
|
||||
\Amp\once('\Amp\stop', $msDelay = 50);
|
||||
\Amp\run();
|
||||
$this->assertEquals(0, $increment);
|
||||
$this->assertEquals(0, \Amp\info()["keep_alive"]);
|
||||
\Amp\enable($watcherId);
|
||||
\Amp\once('\Amp\stop', $msDelay = 50);
|
||||
\Amp\run();
|
||||
$this->assertEquals(1, $increment);
|
||||
}
|
||||
|
||||
public function testUnresolvedEventsAreReenabledOnRunFollowingPreviousStop() {
|
||||
$increment = 0;
|
||||
\Amp\once(function () use (&$increment) {
|
||||
$increment++;
|
||||
\Amp\stop();
|
||||
}, $msDelay = 150);
|
||||
|
||||
\Amp\run('\Amp\stop');
|
||||
|
||||
$this->assertEquals(0, $increment);
|
||||
\usleep(150000);
|
||||
\Amp\run();
|
||||
$this->assertEquals(1, $increment);
|
||||
}
|
||||
|
||||
public function testTimerWatcherParameterOrder() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user