Revert "改名"
This reverts commit fdf58326
This commit is contained in:
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
Coroutine\defer(function () {
|
||||
$this->handler();
|
||||
});
|
||||
$data = $this->channel->pop(-1);
|
||||
|
||||
$task = new Task();
|
||||
$task->data = $data;
|
||||
|
||||
$this->taskServer->onCoroutineTask(null, $task);
|
||||
|
||||
$this->handler();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user