(
condition: () => boolean | Promise<boolean>,
options?: { timeoutMs?: number; intervalMs?: number }
)
| 36 | * `workspaceGoalService.test.ts` and `idleDispatcher.test.ts`. |
| 37 | */ |
| 38 | export 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` |
no outgoing calls
no test coverage detected