MCPcopy Create free account
hub / github.com/cloudflare/moltworker / waitForProcess

Function waitForProcess

src/gateway/utils.ts:12–27  ·  view source on GitHub ↗
(
  proc: { status: string; getStatus?: () => Promise<string> },
  timeoutMs: number,
  pollIntervalMs: number = 500,
)

Source from the content-addressed store, hash-verified

10 * @param pollIntervalMs - How often to check status (default 500ms)
11 */
12export 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}

Callers 2

api.tsFile · 0.90
debug.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected