From 85a1b6e3997f17791e8b1d88244c71e9985037bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 19 Apr 2021 11:52:23 +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 --- Annotation/LocalService.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Annotation/LocalService.php b/Annotation/LocalService.php index 984d792d..2edc4892 100644 --- a/Annotation/LocalService.php +++ b/Annotation/LocalService.php @@ -19,11 +19,19 @@ use Snowflake\Snowflake; /** * LocalService constructor. * @param string $service - * @param array $args + * @param array|null $args * @param bool $async_reload + * @throws Exception */ - public function __construct(public string $service, public array $args = [], public bool $async_reload = true) + public function __construct(public string $service, public ?array $args = [], public bool $async_reload = true) { + if ($this->async_reload !== true) { + return; + } + $event = Snowflake::app()->getEvent(); + $event->on(Event::SERVER_WORKER_EXIT, function () { + Snowflake::app()->remove($this->service); + }); } @@ -40,18 +48,9 @@ use Snowflake\Snowflake; } Snowflake::set($this->service, $class); -// if ($this->async_reload === true) { -// $event = Snowflake::app()->getEvent(); -// $event->on(Event::SERVER_WORKER_EXIT, [$this, 'clear']); -// } return parent::execute($handler); // TODO: Change the autogenerated stub } - public function clear() - { - Snowflake::app()->remove($this->service); - } - }