Revert "改名"

This reverts commit fdf58326
This commit is contained in:
2022-02-03 14:54:38 +08:00
parent 8296cda1f2
commit 4d6f7d1d13
3 changed files with 60 additions and 5 deletions
+3 -3
View File
@@ -12,19 +12,19 @@ namespace Kiri\Abstracts;
use Database\Connection;
use Exception;
use Kiri\Message\Handler\Router;
use Kafka\KafkaProvider;
use Kiri\Async;
use Kiri;
use Kiri\Annotation\Annotation as SAnnotation;
use Kiri\Async;
use Kiri\Cache\Redis;
use Kiri\Di\LocalService;
use Kiri\Error\{ErrorHandler, Logger};
use Kiri\Exception\{InitException, NotFindClassException};
use ReflectionException;
use Kiri\Message\Handler\Router;
use Kiri\Server\{Server, ServerManager};
use Kiri\Task\AsyncTaskExecute;
use Kiri\Task\OnTaskInterface;
use ReflectionException;
use Swoole\Table;
/**
+54
View File
@@ -0,0 +1,54 @@
<?php
namespace Kiri\Server;
use Kiri\Abstracts\Component;
use Kiri\Abstracts\Config;
use Kiri\Exception\ConfigException;
use Kiri\Task\OnServerTask;
use Swoole\Coroutine;
use Swoole\Coroutine\Channel;
use Swoole\Server\Task;
class CoroutineTasker extends Component
{
public Channel $channel;
/**
* @return void
* @throws ConfigException
*/
public function initCore()
{
$taskWorker = Config::get('server.settings.task_worker_num', 0);
if ($taskWorker > 1) {
$this->channel = new Channel($taskWorker);
for ($i = 0; $i < $taskWorker; $i++) {
Coroutine::create(function () {
while ($this->channel->capacity) {
$data = $this->channel->pop(-1);
$execute = $this->getContainer()->get(OnServerTask::class);
$task = new Task();
$task->data = $data;
$execute->onCoroutineTask(null, $task);
}
});
}
}
}
public function dispatch($data)
{
$this->channel->push($data);
}
}
+3 -2
View File
@@ -56,14 +56,15 @@ class CoroutineTaskExecute extends Component
*/
protected function handler()
{
Coroutine\defer(function () {
$this->handler();
});
$data = $this->channel->pop(-1);
$task = new Task();
$task->data = $data;
$this->taskServer->onCoroutineTask(null, $task);
$this->handler();
}