forked from Rockachopa/Timmy-time-dashboard
Review Fix: Improve src/infrastructure/ws_manager/handler.py
This commit is contained in:
@@ -79,7 +79,17 @@ class WebSocketManager:
|
||||
message = ws_event.to_json()
|
||||
disconnected = []
|
||||
|
||||
for ws in self._connections:
|
||||
import asyncio
|
||||
tasks = [ws.send_text(message) for ws in self._connections]
|
||||
results = await asyncio.gather(*tasks, return_exceptions=True)
|
||||
|
||||
disconnected = []
|
||||
for ws, result in zip(self._connections, results):
|
||||
if isinstance(result, Exception):
|
||||
logger.warning(f"WebSocket send error: {result}")
|
||||
disconnected.append(ws)
|
||||
|
||||
# Skip the old loop
|
||||
try:
|
||||
await ws.send_text(message)
|
||||
except ConnectionError:
|
||||
|
||||
Reference in New Issue
Block a user