from __future__ import annotations import asyncio import logging from yuxi.channel.extensions.line.bot import LineBotClient logger = logging.getLogger(__name__) DEFAULT_LOADING_SECONDS = 20 DEFAULT_KEEPALIVE_INTERVAL = 18 class LineLoadingManager: async def start_loading_keepalive( self, user_id: str, token: str, stop_event: asyncio.Event, loading_seconds: int = DEFAULT_LOADING_SECONDS, keepalive_interval: int = DEFAULT_KEEPALIVE_INTERVAL, ) -> None: bot = LineBotClient(channel_access_token=token) await bot.show_loading_animation(user_id, loading_seconds) while not stop_event.is_set(): await asyncio.sleep(keepalive_interval) if not stop_event.is_set(): await bot.show_loading_animation(user_id, loading_seconds)