| 10 | * @param pollIntervalMs - How often to check status (default 500ms) |
| 11 | */ |
| 12 | export async function waitForProcess( |
| 13 | proc: { status: string; getStatus?: () => Promise<string> }, |
| 14 | timeoutMs: number, |
| 15 | pollIntervalMs: number = 500, |
| 16 | ): Promise<void> { |
| 17 | const maxAttempts = Math.ceil(timeoutMs / pollIntervalMs); |
| 18 | let attempts = 0; |
| 19 | let currentStatus = proc.status; |
| 20 | while ((currentStatus === 'running' || currentStatus === 'starting') && attempts < maxAttempts) { |
| 21 | // eslint-disable-next-line no-await-in-loop -- intentional sequential polling |
| 22 | await new Promise((r) => setTimeout(r, pollIntervalMs)); |
| 23 | // proc.status is a snapshot; must call getStatus() to refresh |
| 24 | currentStatus = proc.getStatus ? await proc.getStatus() : proc.status; // eslint-disable-line no-await-in-loop -- intentional sequential polling |
| 25 | attempts++; |
| 26 | } |
| 27 | } |