Revert "改名"
This reverts commit fdf58326
This commit is contained in:
@@ -12,19 +12,19 @@ namespace Kiri\Abstracts;
|
|||||||
|
|
||||||
use Database\Connection;
|
use Database\Connection;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri\Message\Handler\Router;
|
|
||||||
use Kafka\KafkaProvider;
|
use Kafka\KafkaProvider;
|
||||||
use Kiri\Async;
|
|
||||||
use Kiri;
|
use Kiri;
|
||||||
use Kiri\Annotation\Annotation as SAnnotation;
|
use Kiri\Annotation\Annotation as SAnnotation;
|
||||||
|
use Kiri\Async;
|
||||||
use Kiri\Cache\Redis;
|
use Kiri\Cache\Redis;
|
||||||
use Kiri\Di\LocalService;
|
use Kiri\Di\LocalService;
|
||||||
use Kiri\Error\{ErrorHandler, Logger};
|
use Kiri\Error\{ErrorHandler, Logger};
|
||||||
use Kiri\Exception\{InitException, NotFindClassException};
|
use Kiri\Exception\{InitException, NotFindClassException};
|
||||||
use ReflectionException;
|
use Kiri\Message\Handler\Router;
|
||||||
use Kiri\Server\{Server, ServerManager};
|
use Kiri\Server\{Server, ServerManager};
|
||||||
use Kiri\Task\AsyncTaskExecute;
|
use Kiri\Task\AsyncTaskExecute;
|
||||||
use Kiri\Task\OnTaskInterface;
|
use Kiri\Task\OnTaskInterface;
|
||||||
|
use ReflectionException;
|
||||||
use Swoole\Table;
|
use Swoole\Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -56,14 +56,15 @@ class CoroutineTaskExecute extends Component
|
|||||||
*/
|
*/
|
||||||
protected function handler()
|
protected function handler()
|
||||||
{
|
{
|
||||||
|
Coroutine\defer(function () {
|
||||||
|
$this->handler();
|
||||||
|
});
|
||||||
$data = $this->channel->pop(-1);
|
$data = $this->channel->pop(-1);
|
||||||
|
|
||||||
$task = new Task();
|
$task = new Task();
|
||||||
$task->data = $data;
|
$task->data = $data;
|
||||||
|
|
||||||
$this->taskServer->onCoroutineTask(null, $task);
|
$this->taskServer->onCoroutineTask(null, $task);
|
||||||
|
|
||||||
$this->handler();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user