| 1 |
""" |
| 2 |
Assemble components into an app that shall be tested |
| 3 |
""" |
| 4 |
|
| 5 |
from typing import AsyncGenerator |
| 6 |
|
| 7 |
from litestar import Litestar, get |
| 8 |
from litestar.response import ServerSentEvent |
| 9 |
from litestar.types import SSEData |
| 10 |
|
| 11 |
|
| 12 |
async def generator(topic: str) -> AsyncGenerator[SSEData, None]: |
| 13 |
count = 0 |
| 14 |
while count < 2: |
| 15 |
yield topic |
| 16 |
count += 1 |
| 17 |
|
| 18 |
|
| 19 |
@get("/notify/{topic:str}") |
| 20 |
async def get_notified(topic: str) -> ServerSentEvent: |
| 21 |
return ServerSentEvent(generator(topic), event_type="Notifier") |
| 22 |
|
| 23 |
|
| 24 |
app = Litestar(route_handlers=[get_notified]) |