Skip to content

Commit

Permalink
fix ystore start flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Jialin Zhang committed May 2, 2024
1 parent aa48250 commit 8a225c3
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 self.db_initialized is not None 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 self.db_initialized is None:
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 self.db_initialized is None:
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 8a225c3

Please sign in to comment.