(
predicate: () => boolean | Promise<boolean>,
{
timeoutMs = 30_000,
intervalMs = 100,
timeoutMessage = "Timed out waiting for condition.",
}: { timeoutMs?: number; intervalMs?: number; timeoutMessage?: string } = {}
)
| 128 | } |
| 129 | |
| 130 | export async function waitForCondition( |
| 131 | predicate: () => boolean | Promise<boolean>, |
| 132 | { |
| 133 | timeoutMs = 30_000, |
| 134 | intervalMs = 100, |
| 135 | timeoutMessage = "Timed out waiting for condition.", |
| 136 | }: { timeoutMs?: number; intervalMs?: number; timeoutMessage?: string } = {} |
| 137 | ): Promise<void> { |
| 138 | const deadline = Date.now() + timeoutMs; |
| 139 | while (Date.now() < deadline) { |
| 140 | if (await predicate()) { |
| 141 | return; |
| 142 | } |
| 143 | await new Promise((resolve) => setTimeout(resolve, intervalMs)); |
| 144 | } |
| 145 | throw new Error(timeoutMessage); |
| 146 | } |
searching dependent graphs…