Тест long polling

This commit is contained in:
urec56 2024-07-13 14:39:09 +04:00
parent df3629138c
commit 22902048cd

View file

@ -1,4 +1,5 @@
import asyncio import asyncio
from collections import defaultdict
import websockets import websockets
from fastapi import WebSocket, WebSocketDisconnect, Depends, HTTPException, status from fastapi import WebSocket, WebSocketDisconnect, Depends, HTTPException, status
@ -158,8 +159,8 @@ async def chat_ws(
class PollingManager: class PollingManager:
def __init__(self): def __init__(self):
self.waiters: dict[int, list[asyncio.Future]] = {} self.waiters: dict[int, list[asyncio.Future]] = defaultdict(list)
self.messages: dict[int, list[dict]] = {} self.messages: dict[int, list[dict]] = defaultdict(list)
async def poll(self, chat_id: int): async def poll(self, chat_id: int):
future = asyncio.Future() future = asyncio.Future()