aio-libs / aiohttp-sse

Server-sent events support for aiohttp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Graceful example worked fails on browser reconnect

Olegt0rr opened this issue · comments

Gathering tasks in worker may fail all worker on a single failed connection, since gather will raise an exception.

async def worker(app):
while True:
now = datetime.now()
delay = asyncio.create_task(asyncio.sleep(1)) # Fire
fs = []
for stream in app["streams"]:
data = {
"time": f"Server Time : {now}",
"last_event_id": stream.last_event_id,
}
fs.append(stream.send_json(data, id=now.timestamp()))
# Run in parallel
await asyncio.gather(*fs)
# Sleep 1s - n
await delay