This commit is contained in:
2020-11-27 14:57:58 +08:00
parent cf8866d1ce
commit b7b0274a6e
3 changed files with 46 additions and 17 deletions
+16 -4
View File
@@ -10,6 +10,7 @@ use HttpServer\Route\Annotation\Tcp;
use HttpServer\Route\Annotation\Websocket;
use HttpServer\Route\Annotation\Websocket as AWebsocket;
use Snowflake\Event;
use Snowflake\Exception\ComponentException;
use Snowflake\Snowflake;
use Swoole\Coroutine;
use Swoole\Server;
@@ -32,12 +33,23 @@ class OnClose extends Callback
* @throws Exception
*/
public function onHandler(Server $server, int $fd)
{
Coroutine::defer(function () {
fire(Event::EVENT_AFTER_REQUEST);
});
$this->execute($server, $fd);
}
/**
* @param Server $server
* @param int $fd
* @throws ComponentException
* @throws Exception
*/
private function execute(Server $server, int $fd)
{
try {
$event = Snowflake::app()->getEvent();
Coroutine::defer(function () use ($event) {
$event->trigger(Event::EVENT_AFTER_REQUEST);
});
[$manager, $name] = $this->resolve($server, $fd);
if (empty($manager) || !$manager->has($name)) {
return;