From b4388fd7d28c534289617f402fe25a7986da47ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 1 Mar 2021 15:54:11 +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 --- HttpServer/Events/OnFinish.php | 30 ++++++++++++++++-------------- HttpServer/Events/OnTask.php | 21 +++++++-------------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/HttpServer/Events/OnFinish.php b/HttpServer/Events/OnFinish.php index 2bc7093e..d52d9153 100644 --- a/HttpServer/Events/OnFinish.php +++ b/HttpServer/Events/OnFinish.php @@ -16,19 +16,21 @@ use Swoole\Server; */ class OnFinish extends Callback { - /** - * @param Server $server - * @param $task_id - * @param $data - * @throws Exception - */ - public function onHandler(Server $server, $task_id, $data) - { - try { - fire(Event::TASK_FINISH, [$task_id, $data]); - } catch (\Throwable $exception) { - $this->addError($exception, 'task'); - } - } + /** + * @param Server $server + * @param $task_id + * @param $data + * @throws Exception + */ + public function onHandler(Server $server, $task_id, $data) + { + try { + fire(Event::TASK_FINISH, [$task_id, $data]); + } catch (\Throwable $exception) { + $this->addError($exception, 'task'); + } finally { + Snowflake::app()->decrement(); + } + } } diff --git a/HttpServer/Events/OnTask.php b/HttpServer/Events/OnTask.php index 0152c704..3c208d7f 100644 --- a/HttpServer/Events/OnTask.php +++ b/HttpServer/Events/OnTask.php @@ -48,17 +48,13 @@ class OnTask extends Callback */ public function onTask(Server $server, int $task_id, int $from_id, string $data): mixed { - $app = Snowflake::app()->increment(); - Coroutine\defer(function () use ($app) { - $app->decrement(); - }); - - $time = microtime(TRUE); + Snowflake::app()->increment(); if (empty($data)) { return $server->finish('null data'); } - $finish = $this->runTaskHandler($data); + $time = microtime(TRUE); + $finish = $this->runTaskHandler($data); if (!$finish) { $finish = []; } @@ -78,16 +74,13 @@ class OnTask extends Callback */ public function onContinueTask(Server $server, Server\Task $task): mixed { - $app = Snowflake::app()->increment(); - Coroutine\defer(function () use ($app) { - $app->decrement(); - }); - - $time = microtime(TRUE); + Snowflake::app()->increment(); if (empty($task->data)) { return $task->finish('null data'); } - $finish = $this->runTaskHandler($task->data); + + $time = microtime(TRUE); + $finish = $this->runTaskHandler($task->data); if (!$finish) { $finish = []; }