Hi,
I’m implementing an endpoint to open a notification stream using ServerSentEvent replies. I use an asynchronous generator that is waiting a trigger (in my case a publish on a channel).
I m wondering if I could be able to send an immediate HTTP 200 OK reply even if I’m waiting ?
async def notification_publisher(self, channels: ChannelsPlugin) -> AsyncGenerator[SSEData, None]:
subscriber = await channels.subscribe(["general"])
async for message in subscriber.iter_events():
yield message
@get("/{dynamic_id:uuid}/events", status_code=HTTP_200_OK)
async def subscribe_to_notifications(self, dynamic_id: UUID, channels: ChannelsPlugin) -> ServerSentEvent:
return ServerSentEvent(self.notification_publisher(channels))
In other words, is it possible to generate a response before the first yield is reached ?
Possible to decorrelate the reply to the GET request and the notifications sending ?
Thank you
Florian