This commit is contained in:
as2252258@163.com
2021-03-20 03:25:30 +08:00
parent b7ffd265a1
commit d4295ab8c5
+17 -17
View File
@@ -4,17 +4,10 @@
namespace Snowflake\Process; namespace Snowflake\Process;
use ReflectionException;
use Snowflake\Core\Json;
use Snowflake\Crontab; use Snowflake\Crontab;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\ConfigException;
use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake;
use Swoole\Coroutine; use Swoole\Coroutine;
use Swoole\Coroutine\Barrier; use Swoole\Coroutine\WaitGroup;
use Swoole\Coroutine\Channel; use Swoole\Coroutine\Channel;
use Swoole\Exception;
use Swoole\Timer; use Swoole\Timer;
/** /**
@@ -26,7 +19,7 @@ class CrontabProcess extends Process
private Channel $channel; private Channel $channel;
private Coroutine\WaitGroup $waitGroup; private WaitGroup $waitGroup;
/** @var Crontab[] $names */ /** @var Crontab[] $names */
@@ -39,20 +32,26 @@ class CrontabProcess extends Process
public function onHandler(\Swoole\Process $process): void public function onHandler(\Swoole\Process $process): void
{ {
$this->channel = new Channel(1000); $this->channel = new Channel(1000);
Coroutine\go(function () {
$this->waitGroup = new Coroutine\WaitGroup(); $this->waitGroup();
Coroutine::create(function () {
$this->waitGroup->add(1);
$this->readByCha();
}); });
$this->waitGroup->wait(-1);
while (true) { while (true) {
$this->channel->push($process->read()); $this->channel->push($process->read());
} }
} }
private function waitGroup()
{
$this->waitGroup = new WaitGroup();
$this->waitGroup->add();
Coroutine\go(function () {
$this->readByCha();
});
$this->waitGroup->wait(-1);
}
private function readByCha() private function readByCha()
{ {
try { try {
@@ -118,7 +117,8 @@ class CrontabProcess extends Process
// }; // };
// $timer = $content->getTickTime() * 10; // $timer = $content->getTickTime() * 10;
$this->waitGroup->add(1); $this->waitGroup->add();
var_dump(serialize($content)); var_dump(serialize($content));