Skip to content

Commit

Permalink
Merge pull request #40 from jzhang20133/ystore-fix
Browse files Browse the repository at this point in the history
fix ystore start flow
  • Loading branch information
Zsailer authored May 2, 2024
2 parents aa48250 + 7723edd commit 8e85b26
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pycrdt_websocket/ystore.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ def __init__(
self.metadata_callback = metadata_callback
self.log = log or getLogger(__name__)
self.lock = Lock()
self.db_initialized = Event()

async def start(
self,
Expand All @@ -342,7 +341,6 @@ async def start(
Arguments:
task_status: The status to set when the task has started.
"""

self.db_initialized = Event()
if from_context_manager:
assert self._task_group is not None
Expand All @@ -361,7 +359,7 @@ async def start(

async def stop(self) -> None:
"""Stop the store."""
if self.db_initialized.is_set():
if hasattr(self, "db_initialized") and self.db_initialized.is_set():
await self._db.close()
await super().stop()

Expand Down Expand Up @@ -415,6 +413,8 @@ async def read(self) -> AsyncIterator[tuple[bytes, bytes, float]]:
Returns:
A tuple of (update, metadata, timestamp) for each update.
"""
if not hasattr(self, "db_initialized"):
raise RuntimeError("ystore is not started")
await self.db_initialized.wait()
try:
async with self.lock:
Expand All @@ -438,6 +438,8 @@ async def write(self, data: bytes) -> None:
Arguments:
data: The update to store.
"""
if not hasattr(self, "db_initialized"):
raise RuntimeError("ystore is not started")
await self.db_initialized.wait()
async with self.lock:
# first, determine time elapsed since last update
Expand Down

0 comments on commit 8e85b26

Please sign in to comment.