From ce8f8795e3a4ed6e81f0d990ad53ed00525dfbde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Fri, 19 Mar 2021 17:09:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- System/Async.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/System/Async.php b/System/Async.php index 01acdc69..399f99ad 100644 --- a/System/Async.php +++ b/System/Async.php @@ -6,6 +6,7 @@ namespace Snowflake; use Exception; use HttpServer\IInterface\Task; +use ReflectionException; use Snowflake\Abstracts\Component; /** @@ -17,16 +18,22 @@ class Async extends Component /** - * @param Task $class + * @param string $class + * @param array $params * @throws Exception + * @throws ReflectionException */ - public function dispatch(Task $class) + public function dispatch(string $class, array $params) { $server = Snowflake::app()->getSwoole(); if (!isset($server->setting['task_worker_num']) || !class_exists($class)) { return; } + /** @var Task $class */ + $class = Snowflake::createObject($class); + $class->setParams($params); + $randWorkerId = random_int(0, $server->setting['task_worker_num'] - 1); $server->task(serialize($class), $randWorkerId);