改名
This commit is contained in:
@@ -23,6 +23,7 @@ use HttpServer\Service\Receive;
|
||||
use HttpServer\Service\Websocket;
|
||||
use Kafka\Producer;
|
||||
use Annotation\Annotation as SAnnotation;
|
||||
use Snowflake\Async;
|
||||
use Snowflake\Cache\Redis;
|
||||
use Snowflake\Di\Service;
|
||||
use Snowflake\Error\ErrorHandler;
|
||||
@@ -46,6 +47,7 @@ use Database\DatabasesProviders;
|
||||
* @property \Redis|Redis $redis
|
||||
* @property Server $server
|
||||
* @property DatabasesProviders $db
|
||||
* @property Async $async
|
||||
* @property Connection $connections
|
||||
* @property Logger $logger
|
||||
* @property Jwt $jwt
|
||||
@@ -391,6 +393,16 @@ abstract class BaseApplication extends Service
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Async
|
||||
* @throws ComponentException
|
||||
*/
|
||||
public function getAsync(): Async
|
||||
{
|
||||
return $this->get('async');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
@@ -410,6 +422,7 @@ abstract class BaseApplication extends Service
|
||||
'router' => ['class' => Router::class],
|
||||
'redis' => ['class' => Redis::class],
|
||||
'jwt' => ['class' => Jwt::class],
|
||||
'async' => ['class' => Async::class],
|
||||
'goto' => ['class' => BaseGoto::class],
|
||||
'http2' => ['class' => Http2::class],
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Snowflake;
|
||||
|
||||
|
||||
use Exception;
|
||||
use HttpServer\IInterface\Task;
|
||||
use Snowflake\Abstracts\Component;
|
||||
|
||||
/**
|
||||
* Class Async
|
||||
* @package Snowflake
|
||||
*/
|
||||
class Async extends Component
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param Task $class
|
||||
* @throws Exception
|
||||
*/
|
||||
public function dispatch(Task $class)
|
||||
{
|
||||
$server = Snowflake::app()->server->getServer();
|
||||
if (!isset($server->setting['task_worker_num']) || !class_exists($class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$randWorkerId = random_int(0, $server->setting['task_worker_num'] - 1);
|
||||
|
||||
$server->task(serialize($class), $randWorkerId);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user