From 536e4c9bc552ae4a48b1a72bca9872bd17f89aee Mon Sep 17 00:00:00 2001 From: whwyy Date: Fri, 3 Jul 2026 18:29:45 +0800 Subject: [PATCH] eee --- kiri-engine/Coordinator.php | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/kiri-engine/Coordinator.php b/kiri-engine/Coordinator.php index c4544b9b..16353ceb 100644 --- a/kiri-engine/Coordinator.php +++ b/kiri-engine/Coordinator.php @@ -11,7 +11,7 @@ class Coordinator const string WORKER_START = 'worker:start'; - private bool $wait = true; + private bool $wait = false; private ?Channel $channel = null; @@ -22,12 +22,17 @@ class Coordinator public function yield(): void { if (Coroutine::getCid() > 0) { - $this->channel = new Channel(1); - $this->channel->pop(); - } else { - while ($this->wait) { - usleep(1000); + if ($this->channel instanceof Channel) { + $this->channel->pop(); } + return; + } + + if ($this->wait === false) { + return; + } + while ($this->wait === true) { + usleep(1000); } } @@ -37,8 +42,7 @@ class Coordinator */ public function wait(): void { - $this->wait = true; - $this->channel = null; + Coroutine::getCid() > 0 ? $this->channel = new Channel(1) : $this->wait = true; } @@ -47,8 +51,13 @@ class Coordinator */ public function done(): void { - $this->wait = false; - $this->channel?->push(true); + if (Coroutine::getCid() > 0) { + $this->channel?->push(true); + $this->channel->close(); + $this->channel = null; + } else { + $this->wait = false; + } } }