Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make disconnect wait for main_task #200

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions livekit-rtc/livekit/rtc/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import asyncio
import contextlib

Check failure on line 16 in livekit-rtc/livekit/rtc/room.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F401)

livekit-rtc/livekit/rtc/room.py:16:8: F401 `contextlib` imported but unused
import ctypes
import logging
from dataclasses import dataclass, field
Expand Down Expand Up @@ -217,23 +218,25 @@
self._task = self._loop.create_task(self._listen_task())

async def disconnect(self) -> None:
if not self.isconnected():
return
try:
if self.isconnected():
req = proto_ffi.FfiRequest()
req.disconnect.room_handle = self._ffi_handle.handle # type: ignore

req = proto_ffi.FfiRequest()
req.disconnect.room_handle = self._ffi_handle.handle # type: ignore
queue = FfiClient.instance.queue.subscribe()
try:
resp = FfiClient.instance.request(req)
await queue.wait_for(
lambda e: e.disconnect.async_id == resp.disconnect.async_id
)
finally:
FfiClient.instance.queue.unsubscribe(queue)

queue = FfiClient.instance.queue.subscribe()
try:
resp = FfiClient.instance.request(req)
await queue.wait_for(
lambda e: e.disconnect.async_id == resp.disconnect.async_id
)
if self._task is not None:
await self._task
finally:
FfiClient.instance.queue.unsubscribe(queue)

await self._task
FfiClient.instance.queue.unsubscribe(self._ffi_queue)
if self._ffi_queue is not None:
FfiClient.instance.queue.unsubscribe(self._ffi_queue)

async def _listen_task(self) -> None:
# listen to incoming room events
Expand Down
Loading