This commit is contained in:
2026-06-12 23:57:25 +08:00
parent ca8cc081bc
commit 8479106b9f
12 changed files with 148 additions and 286 deletions
+19 -9
View File
@@ -1,15 +1,19 @@
<?php
declare(strict_types=1);
namespace Kiri;
use Swoole\Coroutine;
use Swoole\Coroutine\Channel;
class Coordinator
{
const string WORKER_START = 'worker:start';
private bool $waite = true;
private bool $wait = true;
private ?Channel $channel = null;
/**
@@ -17,18 +21,24 @@ class Coordinator
*/
public function yield(): void
{
while ($this->waite) {
usleep(1000);
}
if (Coroutine::getCid() > 0) {
$this->channel = new Channel(1);
$this->channel->pop();
} else {
while ($this->wait) {
usleep(1000);
}
}
}
/**
* @return void
*/
public function waite(): void
public function wait(): void
{
$this->waite = true;
$this->wait = true;
$this->channel = null;
}
@@ -37,8 +47,8 @@ class Coordinator
*/
public function done(): void
{
$this->waite = false;
$this->wait = false;
$this->channel?->push(true);
}
}