Skip to content

Commit

Permalink
Type get_room as possible coroutine (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart authored Jun 19, 2023
1 parent 805777d commit 55b5fb6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ypy_websocket/websocket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from contextlib import AsyncExitStack
from inspect import isawaitable
from logging import Logger, getLogger
from typing import Awaitable, cast

from anyio import TASK_STATUS_IGNORED, Event, create_task_group
from anyio.abc import TaskGroup, TaskStatus
Expand Down Expand Up @@ -56,7 +57,7 @@ def started(self) -> Event:
self._started = Event()
return self._started

def get_room(self, name: str) -> YRoom:
def get_room(self, name: str) -> YRoom | Awaitable[YRoom]:
"""Get or create a room with the given name.
Arguments:
Expand Down Expand Up @@ -130,6 +131,7 @@ async def _serve(self, websocket, *, task_status: TaskStatus[None] = TASK_STATUS
room = self.get_room(websocket.path)
if isawaitable(room):
room = await room
room = cast(YRoom, room)
if not room.started.is_set():
tg.start_soon(room.start)
await room.started.wait()
Expand Down

0 comments on commit 55b5fb6

Please sign in to comment.