from __future__ import annotations import asyncio from collections.abc import Callable Predicate = Callable[[], bool] async def wait_until( predicate: Predicate, *, timeout_seconds: float = 3.0, ) -> None: """Дождаться наблюдаемого условия без фиксированной длинной паузы.""" async with asyncio.timeout(timeout_seconds): while not predicate(): await asyncio.sleep(0.005)