fix: Улучшение awaitable запросов

This commit is contained in:
AURUMVORXX
2025-10-31 21:36:18 +05:00
parent 5656e903ba
commit 13d4a69ad2

View File

@@ -33,7 +33,7 @@ class Server:
cls._register_routes(app) cls._register_routes(app)
@classmethod @classmethod
async def publish(cls, topic: str, message) -> asyncio.Future: def publish(cls, topic: str, message) -> asyncio.Future:
if topic not in cls._topics: if topic not in cls._topics:
raise KeyError('Клиентов прослушивающих этот топик не существует') raise KeyError('Клиентов прослушивающих этот топик не существует')
@@ -43,11 +43,14 @@ class Server:
# Меняем синтаксис под Squirrel # Меняем синтаксис под Squirrel
data = data.replace("'", '\\"').replace('True', 'true').replace('False', 'false') data = data.replace("'", '\\"').replace('True', 'true').replace('False', 'false')
asyncio.create_task(cls._send_to_topic(topic, data))
return request
@classmethod
async def _send_to_topic(cls, topic, data):
for connection in cls._topics[topic]: for connection in cls._topics[topic]:
await connection.send_text(data) await connection.send_text(data)
return request
@classmethod @classmethod
async def send(cls, connection: WebSocket, message, uuid: str): async def send(cls, connection: WebSocket, message, uuid: str):
data = { data = {
@@ -135,7 +138,7 @@ class Server:
case {'event': event, **kwargs}: case {'event': event, **kwargs}:
try: try:
cls._requests[kwargs['uuid']].set_result(kwargs) cls._requests[kwargs['uuid']].set_result(kwargs.get('data'))
except KeyError: except KeyError:
uuid = kwargs.get('uuid') uuid = kwargs.get('uuid')
if uuid is not None: if uuid is not None: