Skip to content

Commit 7ef1f63

Browse files
committed
Run message processing in background tasks
1 parent 2ab9808 commit 7ef1f63

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

meeseeks/core.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ def _init_apps(self) -> list[_T]:
137137

138138
return app_instances
139139

140-
async def loop(self) -> None:
141-
"""Method is intended for calling in endless loop to process Rocket.Chat callbacks. """
140+
async def message_handler(self, message) -> None:
141+
"""Serializes message context and run processing for each app. """
142142

143-
raw_context: WebSocketClientProtocol = json.loads(await self._websocket.recv())
143+
raw_context: WebSocketClientProtocol = json.loads(message)
144144
if raw_context.get('msg') == 'ping':
145145
await self._rtapi.pong()
146146
return None
@@ -193,9 +193,11 @@ async def run(self) -> None:
193193
self.check_app_name(app)
194194
await app.setup()
195195

196-
while True:
196+
async for message in websocket:
197197
try:
198-
await self.loop()
198+
task = asyncio.create_task(self.message_handler(message))
199+
background_tasks = {task}
200+
task.add_done_callback(background_tasks.discard)
199201
except ClientResponseError as exc:
200202
LOGGER.error(exc)
201203
except ConnectionClosedOK:

0 commit comments

Comments
 (0)