Skip to content

Commit 97f6872

Browse files
author
Jialin Zhang
committed
change yroom class attribute to instance attribute and stop ystore in stop method
1 parent 1cd727f commit 97f6872

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

pycrdt_websocket/yroom.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ class YRoom:
3737
_on_message: Callable[[bytes], Awaitable[bool] | bool] | None
3838
_update_send_stream: MemoryObjectSendStream
3939
_update_receive_stream: MemoryObjectReceiveStream
40-
_task_group: TaskGroup | None = None
41-
_started: Event | None = None
40+
_task_group: TaskGroup | None
41+
_started: Event | None
4242
_stopped: Event
43-
__start_lock: Lock | None = None
44-
_subscription: Subscription | None = None
45-
43+
__start_lock: Lock | None
44+
_subscription: Subscription | None
45+
4646
def __init__(
4747
self,
4848
ready: bool = True,
@@ -82,7 +82,11 @@ def __init__(
8282
self._on_message = None
8383
self.exception_handler = exception_handler
8484
self._stopped = Event()
85-
85+
self._task_group = None
86+
self._started = None
87+
self.__start_lock = None
88+
self._subscription = None
89+
8690
@property
8791
def _start_lock(self) -> Lock:
8892
if self.__start_lock is None:
@@ -230,6 +234,11 @@ async def stop(self) -> None:
230234
self._stopped.set()
231235
self._task_group.cancel_scope.cancel()
232236
self._task_group = None
237+
if self.ystore is not None:
238+
try:
239+
await self.ystore.stop()
240+
except RuntimeError:
241+
pass
233242
if self._subscription is not None:
234243
self.ydoc.unobserve(self._subscription)
235244

0 commit comments

Comments
 (0)