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); - } - }