From a35810d9d412e3a053db285113a3c7197ca8b855 Mon Sep 17 00:00:00 2001 From: Jialin Zhang Date: Mon, 29 Apr 2024 17:47:37 -0700 Subject: [PATCH] change yroom class attribute to instance attribute --- pycrdt_websocket/yroom.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pycrdt_websocket/yroom.py b/pycrdt_websocket/yroom.py index a2a8b3d..1b8dbc1 100644 --- a/pycrdt_websocket/yroom.py +++ b/pycrdt_websocket/yroom.py @@ -37,12 +37,12 @@ class YRoom: _on_message: Callable[[bytes], Awaitable[bool] | bool] | None _update_send_stream: MemoryObjectSendStream _update_receive_stream: MemoryObjectReceiveStream - _task_group: TaskGroup | None = None - _started: Event | None = None + _task_group: TaskGroup | None + _started: Event | None _stopped: Event - __start_lock: Lock | None = None - _subscription: Subscription | None = None - + __start_lock: Lock | None + _subscription: Subscription | None + def __init__( self, ready: bool = True, @@ -82,7 +82,11 @@ def __init__( self._on_message = None self.exception_handler = exception_handler self._stopped = Event() - + self._task_group = None + self._started = None + self.__start_lock = None + self._subscription = None + @property def _start_lock(self) -> Lock: if self.__start_lock is None: @@ -230,6 +234,7 @@ async def stop(self) -> None: self._stopped.set() self._task_group.cancel_scope.cancel() self._task_group = None + await self.ystore.stop() if self._subscription is not None: self.ydoc.unobserve(self._subscription)