This commit is contained in:
2021-04-19 11:52:23 +08:00
parent 4a72b0bdc2
commit 85a1b6e399
+10 -11
View File
@@ -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);
}
}