Skip to content

Commit

Permalink
Start ystore in a task
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed May 6, 2024
1 parent d4186b7 commit e33d0a9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion jupyter_collaboration/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(
self._cleaner: asyncio.Task | None = None
self._saving_document: asyncio.Task | None = None
self._messages: dict[str, asyncio.Lock] = {}
self._background_tasks = set()

# Listen for document changes
self._document.observe(self._on_document_change)
Expand Down Expand Up @@ -100,7 +101,9 @@ async def initialize(self) -> None:
# try to apply Y updates from the YStore for this document
read_from_source = True
if self.ystore is not None:
await self.ystore.started.wait()
if not self.ystore.started.is_set():
self.create_task(self.ystore.start())
await self.ystore.started.wait()
try:
await self.ystore.apply_updates(self.ydoc)
self._emit(
Expand Down Expand Up @@ -174,6 +177,11 @@ async def stop(self) -> None:
self._document.unobserve()
self._file.unobserve(self.room_id)

def create_task(self, aw):
task = asyncio.create_task(aw)
self._background_tasks.add(task)
task.add_done_callback(self._background_tasks.discard)

async def _broadcast_updates(self):
# FIXME should be upstreamed
try:
Expand Down

0 comments on commit e33d0a9

Please sign in to comment.