Function
waitUntil
(label: string, fn: () => Promise<T | null>, timeoutMs = 5_000)
Source from the content-addressed store, hash-verified
| 152 | } |
| 153 | |
| 154 | async function waitUntil<T>(label: string, fn: () => Promise<T | null>, timeoutMs = 5_000) { |
| 155 | const deadline = Date.now() + timeoutMs; |
| 156 | let lastError: unknown; |
| 157 | |
| 158 | while (Date.now() < deadline) { |
| 159 | try { |
| 160 | const value = await fn(); |
| 161 | if (value !== null) { |
| 162 | return value; |
| 163 | } |
| 164 | } catch (error) { |
| 165 | lastError = error; |
| 166 | } |
| 167 | await Bun.sleep(25); |
| 168 | } |
| 169 | |
| 170 | throw new Error( |
| 171 | `Timed out waiting for ${label}.${lastError ? ` Last error: ${String(lastError)}` : ""}`, |
| 172 | ); |
| 173 | } |
| 174 | |
| 175 | async function readHealth(port: number): Promise<HealthResponse | null> { |
| 176 | try { |
Tested by
no test coverage detected