@@ -139,10 +139,11 @@ def _handle_yroom_stopping(self, room_id: str) -> None:
139139 self ._rooms_by_id .pop (room_id , None )
140140
141141
142- async def delete_room (self , room_id : str ) -> None :
142+ def delete_room (self , room_id : str ) -> None :
143143 """
144- Gracefully deletes a YRoom given a room ID. This stops the YRoom first,
145- which finishes applying all updates & saves the content automatically.
144+ Gracefully deletes a YRoom given a room ID. This stops the YRoom,
145+ closing all Websockets, applying remaining updates, and saves the final
146+ content of the YDoc in a background task.
146147
147148 Returns `True` if the room was deleted successfully. Returns `False` if
148149 an exception was raised.
@@ -153,12 +154,12 @@ async def delete_room(self, room_id: str) -> None:
153154
154155 self .log .info (f"Stopping YRoom '{ room_id } '." )
155156 try :
156- await yroom .stop ()
157- self .log .info (f"Stopped YRoom '{ room_id } '." )
157+ yroom .stop ()
158158 return True
159159 except Exception as e :
160- self .log .error (f"Exception raised when stopping YRoom '{ room_id } :" )
161- self .log .exception (e )
160+ self .log .exception (
161+ f"Exception raised when stopping YRoom '{ room_id } : "
162+ )
162163 return False
163164
164165 async def _watch_rooms (self ) -> None :
@@ -223,35 +224,30 @@ async def _watch_rooms(self) -> None:
223224 self ._inactive_rooms .add (room_id )
224225
225226
226- async def stop (self ) -> None :
227+ def stop (self ) -> None :
227228 """
228229 Gracefully deletes each `YRoom`. See `delete_room()` for more info.
229230 """
230231 # First, stop all background tasks
231232 self ._watch_rooms_task .cancel ()
232233
233- # Get all room IDs. If there are none, return early, as all rooms are
234- # already stopped.
234+ # Get all room IDs. If there are none, return early.
235235 room_ids = list (self ._rooms_by_id .keys ())
236236 room_count = len (room_ids )
237237 if room_count == 0 :
238238 return
239239
240- # Delete rooms in parallel.
241- # Note that we do not use `asyncio.TaskGroup` here because that cancels
242- # all other tasks when any task raises an exception.
240+ # Otherwise, delete all rooms.
243241 self .log .info (
244242 f"Stopping `YRoomManager` and deleting all { room_count } YRooms."
245243 )
246- deletion_tasks = []
244+ failures = 0
247245 for room_id in room_ids :
248- dt = asyncio .create_task (self .delete_room (room_id ))
249- deletion_tasks .append (dt )
250-
251- # Use returned values to log success/failure of room deletion
252- results : list [bool ] = await asyncio .gather (* deletion_tasks )
253- failures = results .count (False )
246+ result = self .delete_room (room_id )
247+ if not result :
248+ failures += 1
254249
250+ # Log the aggregate status before returning.
255251 if failures :
256252 self .log .error (
257253 "An exception occurred when stopping `YRoomManager`. "
0 commit comments