From e8c4a729a52e0a2f3679027ff3ac4a006ca28e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Sat, 22 Apr 2023 02:46:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Task/Task.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Task/Task.php b/Task/Task.php index dcbb0ed..5da5582 100644 --- a/Task/Task.php +++ b/Task/Task.php @@ -65,19 +65,25 @@ class Task implements TaskInterface /** - * @param array $handler + * @param array|string|object $handler * @param int|null $workerId * @return void - * @throws + * @throws ReflectionException */ - public function dispatch(array $handler, ?int $workerId = null): void + public function dispatch(array|string|object $handler, ?int $workerId = null): void { /** @var Server $server */ $server = \Kiri::service()->get('server'); if (is_null($workerId)) { $workerId = rand(0, $server->setting[Constant::OPTION_TASK_WORKER_NUM] - 1); } - $server->task(json_encode($handler), $workerId); + if (is_string($handler)) { + $server->task(serialize([di($handler), 'handle']), $workerId); + } else if (is_string($handler[0])) { + $server->task(serialize($handler), $workerId); + } else { + $server->task(serialize([$handler, 'handle']), $workerId); + } }