Takes a coroutine `func(session)`, and returns an ASGI application.
(
func: Callable[[WebSocket], Awaitable[None]],
)
| 67 | |
| 68 | |
| 69 | def websocket_session( |
| 70 | func: Callable[[WebSocket], Awaitable[None]], |
| 71 | ) -> ASGIApp: |
| 72 | """ |
| 73 | Takes a coroutine `func(session)`, and returns an ASGI application. |
| 74 | """ |
| 75 | # assert asyncio.iscoroutinefunction(func), "WebSocket endpoints must be async" |
| 76 | |
| 77 | async def app(scope: Scope, receive: Receive, send: Send) -> None: |
| 78 | session = WebSocket(scope, receive=receive, send=send) |
| 79 | |
| 80 | async def app(scope: Scope, receive: Receive, send: Send) -> None: |
| 81 | await func(session) |
| 82 | |
| 83 | await wrap_app_handling_exceptions(app, session)(scope, receive, send) |
| 84 | |
| 85 | return app |
| 86 | |
| 87 | |
| 88 | def get_name(endpoint: Callable[..., Any]) -> str: |