客户端正常停止也调用回调

This commit is contained in:
John Smith 2023-09-05 19:23:20 +08:00
parent e99dc7c5a3
commit e9d4bf47cf
2 changed files with 6 additions and 4 deletions

View File

@ -232,8 +232,8 @@ class WebSocketClientBase:
logger.debug('room=%s _network_coroutine() finished', self.room_id) logger.debug('room=%s _network_coroutine() finished', self.room_id)
self._network_future = None self._network_future = None
if exc is not None and self._handler is not None: if self._handler is not None:
self._handler.on_stopped_by_exception(self, exc) self._handler.on_client_stopped(self, exc)
async def _network_coroutine(self): async def _network_coroutine(self):
""" """
@ -454,6 +454,8 @@ class WebSocketClientBase:
:param command: 业务消息 :param command: 业务消息
""" """
if self._handler is None:
return
try: try:
# 为什么不做成异步的: # 为什么不做成异步的:
# 1. 为了保持处理消息的顺序这里不使用call_soon、create_task等方法延迟处理 # 1. 为了保持处理消息的顺序这里不使用call_soon、create_task等方法延迟处理

View File

@ -48,9 +48,9 @@ class HandlerInterface:
def handle(self, client: ws_base.WebSocketClientBase, command: dict): def handle(self, client: ws_base.WebSocketClientBase, command: dict):
raise NotImplementedError raise NotImplementedError
def on_stopped_by_exception(self, client: ws_base.WebSocketClientBase, exception: Exception): def on_client_stopped(self, client: ws_base.WebSocketClientBase, exception: Optional[Exception]):
""" """
当客户端被异常停止时调用可以在这里close或者重新start 当客户端停止时调用可以在这里close或者重新start
""" """