diff --git a/src/pyg2o/server.py b/src/pyg2o/server.py index 4452e76..6822ef9 100644 --- a/src/pyg2o/server.py +++ b/src/pyg2o/server.py @@ -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: