MCPcopy
hub / github.com/coder/mux / waitForCondition

Function waitForCondition

src/node/services/testDispatchHelpers.ts:38–54  ·  view source on GitHub ↗
(
  condition: () => boolean | Promise<boolean>,
  options?: { timeoutMs?: number; intervalMs?: number }
)

Source from the content-addressed store, hash-verified

36 * `workspaceGoalService.test.ts` and `idleDispatcher.test.ts`.
37 */
38export async function waitForCondition(
39 condition: () => boolean | Promise<boolean>,
40 options?: { timeoutMs?: number; intervalMs?: number }
41): Promise<void> {
42 const timeoutMs = options?.timeoutMs ?? 1_000;
43 const intervalMs = options?.intervalMs ?? 5;
44 const deadline = Date.now() + timeoutMs;
45
46 while (Date.now() < deadline) {
47 if (await condition()) {
48 return;
49 }
50 await new Promise((resolve) => setTimeout(resolve, intervalMs));
51 }
52
53 throw new Error(`Timed out after ${timeoutMs}ms waiting for condition`);
54}
55
56/**
57 * Register a no-op continuation consumer on a test `WorkspaceGoalService`

Calls

no outgoing calls

Tested by

no test coverage detected