Commit 7ef1f63 1 parent 2ab9808 commit 7ef1f63 Copy full SHA for 7ef1f63
File tree 1 file changed +7
-5
lines changed
1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -137,10 +137,10 @@ def _init_apps(self) -> list[_T]:
137
137
138
138
return app_instances
139
139
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 . """
142
142
143
- raw_context : WebSocketClientProtocol = json .loads (await self . _websocket . recv () )
143
+ raw_context : WebSocketClientProtocol = json .loads (message )
144
144
if raw_context .get ('msg' ) == 'ping' :
145
145
await self ._rtapi .pong ()
146
146
return None
@@ -193,9 +193,11 @@ async def run(self) -> None:
193
193
self .check_app_name (app )
194
194
await app .setup ()
195
195
196
- while True :
196
+ async for message in websocket :
197
197
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 )
199
201
except ClientResponseError as exc :
200
202
LOGGER .error (exc )
201
203
except ConnectionClosedOK :
You can’t perform that action at this time.
0 commit comments