from api_models import API_CORE from fastapi import WebSocket from time import time import asyncio class API_EXTENSION: def __init__(self, api): self.api: API_CORE = api print("PingPong") self.response = { "ping":"pong", "ts": time() } def routes(self): @self.api.app.get("/api/ping") async def call(): return self.response async def wshello(self, websocket: WebSocket): await websocket.send_json({}) @property def tasks(self): async def updateTs(): while 1: self.response["ts"] = time() await asyncio.sleep(1) return [updateTs]