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

Activate watchers at begging of tick instead of end

This commit is contained in:
Aaron Piotrowski 2017-01-06 10:15:54 -06:00
parent 3e0cd85b67
commit fbdc611e44

View File

@ -88,6 +88,13 @@ abstract class Loop extends Driver {
* Executes a single tick of the event loop.
*/
private function tick() {
$this->deferQueue = \array_merge($this->deferQueue, $this->nextTickQueue);
$this->nextTickQueue = [];
$queue = $this->enableQueue;
$this->enableQueue = [];
$this->activate($queue);
try {
foreach ($this->deferQueue as $watcher) {
if (!isset($this->deferQueue[$watcher->id])) {
@ -117,15 +124,6 @@ abstract class Loop extends Driver {
$errorHandler = $this->errorHandler;
$errorHandler($exception);
}
foreach ($this->nextTickQueue as $watcher) {
$this->deferQueue[$watcher->id] = $watcher;
}
$this->nextTickQueue = [];
$queue = $this->enableQueue;
$this->enableQueue = [];
$this->activate($queue);
}
/**