diff --git a/src/EventLoop/Internal/AbstractDriver.php b/src/EventLoop/Internal/AbstractDriver.php index 636648f..0f44c0d 100644 --- a/src/EventLoop/Internal/AbstractDriver.php +++ b/src/EventLoop/Internal/AbstractDriver.php @@ -91,7 +91,6 @@ public function __construct() $this->queueCallback = $this->queue(...); $this->runCallback = function (): ?\Closure { do { - $garbageCollected = false; if ($this->fiber->isTerminated()) { $this->createLoopFiber(); } @@ -100,11 +99,7 @@ public function __construct() if ($result) { // Null indicates the loop fiber terminated without suspending. return $result; } - - while (\gc_collect_cycles()) { - $garbageCollected = true; - } - } while ($garbageCollected && !$this->stopped); + } while (!$this->stopped && \gc_collect_cycles()); return null; }; @@ -120,17 +115,14 @@ public function run(): void throw new \Error(\sprintf("Can't call %s() within a fiber (i.e., outside of {main})", __METHOD__)); } - if ($this->fiber->isTerminated()) { - $this->createLoopFiber(); - } - - /** @noinspection PhpUnhandledExceptionInspection */ - $lambda = $this->fiber->isStarted() ? $this->fiber->resume() : $this->fiber->start(); + $lambda = ($this->runCallback)(); if ($lambda) { $lambda(); - throw new \Error('Interrupt from event loop must throw an exception: ' . ClosureHelper::getDescription($lambda)); + throw new \Error( + 'Interrupt from event loop must throw an exception: ' . ClosureHelper::getDescription($lambda) + ); } }