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