()
| 3769 | queue = await bus.subscribe() |
| 3770 | |
| 3771 | async def _gen() -> AsyncGenerator[bytes, None]: |
| 3772 | yield b": connected\n\n" |
| 3773 | try: |
| 3774 | while True: |
| 3775 | if await request.is_disconnected(): |
| 3776 | break |
| 3777 | try: |
| 3778 | event = await asyncio.wait_for(queue.get(), timeout=15.0) |
| 3779 | payload = json.dumps(event, default=str) |
| 3780 | yield f"data: {payload}\n\n".encode("utf-8") |
| 3781 | except asyncio.TimeoutError: |
| 3782 | yield b": keepalive\n\n" |
| 3783 | finally: |
| 3784 | await bus.unsubscribe(queue) |
| 3785 | |
| 3786 | return StreamingResponse( |
| 3787 | _gen(), |
no test coverage detected