Skip to content

Commit 8e85b26

Browse files
authored
Merge pull request #40 from jzhang20133/ystore-fix
fix ystore start flow
2 parents aa48250 + 7723edd commit 8e85b26

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pycrdt_websocket/ystore.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ def __init__(
329329
self.metadata_callback = metadata_callback
330330
self.log = log or getLogger(__name__)
331331
self.lock = Lock()
332-
self.db_initialized = Event()
333332

334333
async def start(
335334
self,
@@ -342,7 +341,6 @@ async def start(
342341
Arguments:
343342
task_status: The status to set when the task has started.
344343
"""
345-
346344
self.db_initialized = Event()
347345
if from_context_manager:
348346
assert self._task_group is not None
@@ -361,7 +359,7 @@ async def start(
361359

362360
async def stop(self) -> None:
363361
"""Stop the store."""
364-
if self.db_initialized.is_set():
362+
if hasattr(self, "db_initialized") and self.db_initialized.is_set():
365363
await self._db.close()
366364
await super().stop()
367365

@@ -415,6 +413,8 @@ async def read(self) -> AsyncIterator[tuple[bytes, bytes, float]]:
415413
Returns:
416414
A tuple of (update, metadata, timestamp) for each update.
417415
"""
416+
if not hasattr(self, "db_initialized"):
417+
raise RuntimeError("ystore is not started")
418418
await self.db_initialized.wait()
419419
try:
420420
async with self.lock:
@@ -438,6 +438,8 @@ async def write(self, data: bytes) -> None:
438438
Arguments:
439439
data: The update to store.
440440
"""
441+
if not hasattr(self, "db_initialized"):
442+
raise RuntimeError("ystore is not started")
441443
await self.db_initialized.wait()
442444
async with self.lock:
443445
# first, determine time elapsed since last update

0 commit comments

Comments
 (0)