Skip to content

Commit 607623a

Browse files
committed
Use $runCallback in run()
1 parent af6757c commit 607623a

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

src/EventLoop/Internal/AbstractDriver.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public function __construct()
9191
$this->queueCallback = $this->queue(...);
9292
$this->runCallback = function (): ?\Closure {
9393
do {
94-
$garbageCollected = false;
9594
if ($this->fiber->isTerminated()) {
9695
$this->createLoopFiber();
9796
}
@@ -100,11 +99,7 @@ public function __construct()
10099
if ($result) { // Null indicates the loop fiber terminated without suspending.
101100
return $result;
102101
}
103-
104-
while (\gc_collect_cycles()) {
105-
$garbageCollected = true;
106-
}
107-
} while ($garbageCollected && !$this->stopped);
102+
} while (!$this->stopped && \gc_collect_cycles());
108103

109104
return null;
110105
};
@@ -120,17 +115,14 @@ public function run(): void
120115
throw new \Error(\sprintf("Can't call %s() within a fiber (i.e., outside of {main})", __METHOD__));
121116
}
122117

123-
if ($this->fiber->isTerminated()) {
124-
$this->createLoopFiber();
125-
}
126-
127-
/** @noinspection PhpUnhandledExceptionInspection */
128-
$lambda = $this->fiber->isStarted() ? $this->fiber->resume() : $this->fiber->start();
118+
$lambda = ($this->runCallback)();
129119

130120
if ($lambda) {
131121
$lambda();
132122

133-
throw new \Error('Interrupt from event loop must throw an exception: ' . ClosureHelper::getDescription($lambda));
123+
throw new \Error(
124+
'Interrupt from event loop must throw an exception: ' . ClosureHelper::getDescription($lambda)
125+
);
134126
}
135127
}
136128

0 commit comments

Comments
 (0)