eee
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user