( condition: () => boolean, timeout = 1000, interval = 50, )
| 110 | * Waits for a condition to be true with timeout |
| 111 | */ |
| 112 | export async function waitForCondition( |
| 113 | condition: () => boolean, |
| 114 | timeout = 1000, |
| 115 | interval = 50, |
| 116 | ): Promise<void> { |
| 117 | const startTime = Date.now(); |
| 118 | while (!condition()) { |
| 119 | if (Date.now() - startTime > timeout) { |
| 120 | throw new Error("Timeout waiting for condition"); |
| 121 | } |
| 122 | await new Promise((resolve) => setTimeout(resolve, interval)); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Waits for an async function to not throw |
nothing calls this directly
no test coverage detected
searching dependent graphs…