diff --git a/Server/ApplicationStore.php b/Server/ApplicationStore.php index e21d5738..81c78442 100644 --- a/Server/ApplicationStore.php +++ b/Server/ApplicationStore.php @@ -4,70 +4,83 @@ namespace Server; +use JetBrains\PhpStorm\Pure; use Swoole\Coroutine\Channel; class ApplicationStore { - private static ?ApplicationStore $applicationStore = null; + private static ?ApplicationStore $applicationStore = null; - private Channel $lock; + private Channel $lock; - private function __construct() - { - $this->lock = new Channel(99999); - } + private function __construct() + { + $this->lock = new Channel(99999); + } - /** - * @return \Server\ApplicationStore|null - */ - public static function getStore() - { - if (!(static::$applicationStore instanceof ApplicationStore)) { - static::$applicationStore = new ApplicationStore(); - } - return static::$applicationStore; - } + /** + * @return ApplicationStore|null + */ + public static function getStore(): ?ApplicationStore + { + if (!(static::$applicationStore instanceof ApplicationStore)) { + static::$applicationStore = new ApplicationStore(); + } + return static::$applicationStore; + } - public function add() - { - $this->lock->push(1); - return $this; - } + /** + * @return $this + */ + public function add(): static + { + $this->lock->push(1); + return $this; + } - public function waite() - { - $this->lock->pop(-1); - } + /** + * + */ + public function waite(): void + { + if ($this->lock->isEmpty()) { + return; + } + $this->lock->pop(-1); + } - public function done() - { - $this->lock->pop(); - } + /** + * + */ + public function done(): void + { + $this->lock->pop(); + } - /** - * @return bool - */ - public function isBusy() - { - return !$this->lock->isEmpty(); - } + /** + * @return bool + */ + public function isBusy(): bool + { + return !$this->lock->isEmpty(); + } - /** - * @return string - */ - public function getStatus(): string - { - return env('state'); - } + /** + * @return string + */ + #[Pure] public function getStatus(): string + { + return env('state'); + } } diff --git a/Server/HTTPServerListener.php b/Server/HTTPServerListener.php index 709fa4e5..108e4641 100644 --- a/Server/HTTPServerListener.php +++ b/Server/HTTPServerListener.php @@ -92,6 +92,8 @@ class HTTPServerListener extends Abstracts\Server { try { // defer(fn() => fire(Event::SYSTEM_RESOURCE_RELEASES)); + ApplicationStore::getStore()->waite(); + /** @var \HttpServer\Http\Response $sResponse */ [$sRequest, $sResponse] = $this->request($request, $response); diff --git a/Server/Worker/ServerWorker.php b/Server/Worker/ServerWorker.php index 0e9a8fda..c33cd6a9 100644 --- a/Server/Worker/ServerWorker.php +++ b/Server/Worker/ServerWorker.php @@ -5,6 +5,7 @@ namespace Server\Worker; use Annotation\Annotation; use Exception; use ReflectionException; +use Server\ApplicationStore; use Server\Constant; use Snowflake\Abstracts\Config; use Snowflake\Core\Help; @@ -33,6 +34,9 @@ class ServerWorker extends \Server\Abstracts\Server public function onWorkerStart(Server $server, int $workerId) { $this->_setConfigCache($workerId); + + $store = ApplicationStore::getStore()->add(); + $annotation = Snowflake::app()->getAnnotation(); $annotation->read(APP_PATH . 'app'); @@ -40,6 +44,8 @@ class ServerWorker extends \Server\Abstracts\Server $this->workerInitExecutor($server, $annotation, $workerId); $this->interpretDirectory($annotation); + + $store->done(); }