Skip to content

Commit

Permalink
Use $runCallback in run()
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Dec 7, 2024
1 parent af6757c commit 607623a
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/EventLoop/Internal/AbstractDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public function __construct()
$this->queueCallback = $this->queue(...);
$this->runCallback = function (): ?\Closure {
do {
$garbageCollected = false;
if ($this->fiber->isTerminated()) {
$this->createLoopFiber();
}
Expand All @@ -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;
};
Expand All @@ -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)
);
}
}

Expand Down

0 comments on commit 607623a

Please sign in to comment.