MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / pollUntilTerminal

Function pollUntilTerminal

packages/cli/src/cloud/poll.ts:56–87  ·  view source on GitHub ↗
(
  client: HyperframesCloudClient,
  renderId: string,
  options: PollOptions = {},
)

Source from the content-addressed store, hash-verified

54 * on a retry inside the poll window.
55 */
56export async function pollUntilTerminal(
57 client: HyperframesCloudClient,
58 renderId: string,
59 options: PollOptions = {},
60): Promise<HyperframesRenderDetail> {
61 const intervalMs = options.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;
62 const maxWaitMs = options.maxWaitMs ?? DEFAULT_MAX_WAIT_MS;
63 const now = options.now ?? (() => Date.now());
64 // Default sleep honors the abort signal so Ctrl+C feels immediate
65 // instead of waiting out the full interval. Tests inject a no-op
66 // sleep that ignores the signal — that's fine, they don't abort.
67 const sleep = options.sleep ?? defaultAbortableSleep(options.signal);
68
69 const started = now();
70
71 while (true) {
72 if (options.signal?.aborted) {
73 throw signalAbortError(options.signal);
74 }
75 const detail = await client.getRender({ render_id: renderId, signal: options.signal });
76 const elapsed = now() - started;
77 options.onTick?.(detail, elapsed);
78
79 if (isTerminal(detail.status)) {
80 return detail;
81 }
82 if (elapsed >= maxWaitMs) {
83 throw new PollTimeoutError(detail, elapsed);
84 }
85 await sleep(intervalMs);
86 }
87}
88
89function signalAbortError(signal: AbortSignal): Error {
90 const reason = signal.reason;

Callers 2

poll.test.tsFile · 0.85
pollWithProgressFunction · 0.85

Calls 6

defaultAbortableSleepFunction · 0.85
signalAbortErrorFunction · 0.85
isTerminalFunction · 0.85
nowMethod · 0.80
getRenderMethod · 0.80
sleepFunction · 0.50

Tested by

no test coverage detected