Skip to content

Commit

Permalink
Update CoroutineGen.php
Browse files Browse the repository at this point in the history
  • Loading branch information
VennDev authored Aug 25, 2024
1 parent 0e1b7ca commit b720957
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/vennv/vapm/CoroutineGen.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public static function getTaskQueue(): ?SplQueue
public static function runNonBlocking(mixed ...$coroutines): void
{
System::init();

if (self::$taskQueue === null) self::$taskQueue = new SplQueue();

foreach ($coroutines as $coroutine) {
Expand Down Expand Up @@ -137,10 +138,8 @@ private static function processCoroutine(mixed ...$coroutines): Closure
if (is_callable($coroutine)) {
$coroutine = call_user_func($coroutine);
}

!$coroutine instanceof Generator ? call_user_func(fn() => $coroutine) : self::schedule(new ChildCoroutine($coroutine));
}

self::run();
};
}
Expand All @@ -167,9 +166,7 @@ private static function schedule(ChildCoroutine $childCoroutine): void
*/
public static function run(): void
{
$i = 0;
while (self::$taskQueue?->isEmpty() === false) {
if ($i++ >= 3) break;
if (self::$taskQueue?->isEmpty() === false) {
$coroutine = self::$taskQueue->dequeue();
if ($coroutine instanceof ChildCoroutine) {
$coroutine->run();
Expand Down

0 comments on commit b720957

Please sign in to comment.