Skip to content

Commit

Permalink
Update EventLoop.php
Browse files Browse the repository at this point in the history
  • Loading branch information
VennDev authored Aug 15, 2024
1 parent ffd9885 commit 24ba12a
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/vennv/vapm/simultaneous/EventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use Generator;
use SplQueue;
use Throwable;
use function count;
use const PHP_INT_MAX;

interface EventLoopInterface
Expand Down Expand Up @@ -162,16 +161,10 @@ private static function clearGarbage(): void
*/
protected static function run(): void
{
if (count(GreenThread::getFibers()) > 0) GreenThread::run();

$i = 0;

while (self::$queues->isEmpty() === false) {
if ($i++ >= self::$limit) break;
while (!self::$queues->isEmpty() && $i++ < self::$limit) {
/** @var Promise $promise */
$promise = self::$queues->dequeue();

$id = $promise->getId();
$fiber = $promise->getFiber();

if ($fiber->isSuspended()) {
Expand All @@ -186,14 +179,14 @@ protected static function run(): void
} catch (Throwable $e) {
echo $e->getMessage();
}
MicroTask::addTask($id, $promise);
MicroTask::addTask($promise);

Check failure on line 182 in src/vennv/vapm/simultaneous/EventLoop.php

View workflow job for this annotation

GitHub Actions / Jobs (8.2)

Parameter #1 $id of static method vennv\vapm\simultaneous\MicroTask::addTask() expects int, vennv\vapm\simultaneous\Promise given.

Check failure on line 182 in src/vennv/vapm/simultaneous/EventLoop.php

View workflow job for this annotation

GitHub Actions / Jobs (8.2)

Static method vennv\vapm\simultaneous\MicroTask::addTask() invoked with 1 parameter, 2 required.
} else {
self::$queues->enqueue($promise); // Add to queue again
}
}

if (count(MicroTask::getTasks()) > 0) MicroTask::run();
if (count(MacroTask::getTasks()) > 0) MacroTask::run();
if (!MicroTask::getTasks()->isEmpty()) MicroTask::run();

Check failure on line 188 in src/vennv/vapm/simultaneous/EventLoop.php

View workflow job for this annotation

GitHub Actions / Jobs (8.2)

Cannot call method isEmpty() on array<int, vennv\vapm\simultaneous\Promise>.
if (!MacroTask::getTasks()->isEmpty()) MacroTask::run();

Check failure on line 189 in src/vennv/vapm/simultaneous/EventLoop.php

View workflow job for this annotation

GitHub Actions / Jobs (8.2)

Cannot call method isEmpty() on array<int, vennv\vapm\simultaneous\SampleMacro>.

self::clearGarbage();
}
Expand All @@ -203,8 +196,8 @@ protected static function run(): void
*/
protected static function runSingle(): void
{
self::$limit = min((int)(self::$queues->count() / 2) + 1, 100); // Limit 100 promises per loop
while (self::$queues->isEmpty() === false || count(MicroTask::getTasks()) > 0 || count(MacroTask::getTasks()) > 0 || count(GreenThread::getFibers()) > 0) self::run();
self::$limit = min((int)((self::$queues->count() / 2) + 1), 100); // Limit 100 promises per loop
while (!self::$queues->isEmpty() || !MicroTask::getTasks()->isEmpty() || !MacroTask::getTasks()->isEmpty()) self::run();

Check failure on line 200 in src/vennv/vapm/simultaneous/EventLoop.php

View workflow job for this annotation

GitHub Actions / Jobs (8.2)

Cannot call method isEmpty() on array<int, vennv\vapm\simultaneous\Promise>.

Check failure on line 200 in src/vennv/vapm/simultaneous/EventLoop.php

View workflow job for this annotation

GitHub Actions / Jobs (8.2)

Cannot call method isEmpty() on array<int, vennv\vapm\simultaneous\SampleMacro>.
}

}

0 comments on commit 24ba12a

Please sign in to comment.