```py @websocket( "/ws/{session_id:str},", name="notifications_wss", ) @inject async def ws( self, session_id: str, socket: WebSocket[None, None, State], notification_service: Annotated[NotificationService, Inject], ) -> None: await socket.accept() stop = asyncio.Event() async with asyncio.TaskGroup() as tg: tg.create_task( receive_notifications( socket=socket, notification_service=notification_service, session_id=session_id, stop=stop, ), ) try: async for _ in socket.iter_data("binary"): pass finally: stop.set() ```
You probably want to pass in a asyncio.timeout(None) object then task.reschedule(-1) it when you want to cancel the task