This commit is contained in:
2026-07-03 18:29:45 +08:00
parent 91be2eba20
commit 536e4c9bc5
+19 -10
View File
@@ -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;
}
}
}