MCPcopy Create free account
hub / github.com/github/copilot-sdk / _wait_for

Function _wait_for

python/test_commands_and_elicitation.py:28–40  ·  view source on GitHub ↗

Poll predicate until True or timeout. Replaces brittle ``asyncio.sleep`` waits. Used in unit tests where we dispatch an event and need to wait for the consumer coroutine to invoke a handler and (sometimes) for the handler to issue an RPC that our mock captures. Polling at 5ms means fast

(predicate: Callable[[], bool], timeout: float = 2.0)

Source from the content-addressed store, hash-verified

26
27
28async def _wait_for(predicate: Callable[[], bool], timeout: float = 2.0) -> None:
29 """Poll predicate until True or timeout. Replaces brittle ``asyncio.sleep`` waits.
30
31 Used in unit tests where we dispatch an event and need to wait for the consumer
32 coroutine to invoke a handler and (sometimes) for the handler to issue an RPC
33 that our mock captures. Polling at 5ms means fast machines exit quickly while
34 slow machines still get up to ``timeout`` seconds before the test fails.
35 """
36 deadline = asyncio.get_event_loop().time() + timeout
37 while not predicate():
38 if asyncio.get_event_loop().time() >= deadline:
39 raise AssertionError(f"Condition not met within {timeout}s")
40 await asyncio.sleep(0.005)
41
42
43# ============================================================================

Calls 1

predicateFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…