pollUntilComplete() — typescript-sdk Function Reference
Architecture documentation for the pollUntilComplete() function in async.ts from the typescript-sdk codebase.
Entity Profile
Dependency Diagram
graph TD eacbc0fc_6067_7424_3b32_066d8839c732["pollUntilComplete()"] 0df83784_3dd1_6369_ad77_a87c189f8f77["sleepWithAbort()"] eacbc0fc_6067_7424_3b32_066d8839c732 -->|calls| 0df83784_3dd1_6369_ad77_a87c189f8f77 style eacbc0fc_6067_7424_3b32_066d8839c732 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/async.ts lines 198–266
async function pollUntilComplete<T, R extends AsyncEnvelope<T>>(
apiCall: () => Promise<R>,
options: AsyncClientOptions
): Promise<T> {
const {
timeoutMs = 900000,
defaultRetryIntervalMs = 10000,
maxPollingAttempts = 90,
onPollingProgress,
signal,
} = options;
const startTime = Date.now();
let attempt = 0;
let jobId = '';
while (attempt < maxPollingAttempts) {
// Check for abort before each attempt
if (signal?.aborted) {
const error = new Error('Polling aborted');
error.name = 'AbortError';
throw error;
}
attempt++;
const elapsedMs = Date.now() - startTime;
if (elapsedMs >= timeoutMs) {
throw new PollingTimeoutError(jobId || 'unknown', timeoutMs, attempt);
}
const response = await apiCall();
jobId = response.jobId;
const status = response.status;
if (onPollingProgress) {
const nextRetryMs = status === 'completed' || status === 'failed'
? undefined
: (response.retryAfter || defaultRetryIntervalMs / 1000) * 1000;
onPollingProgress({
jobId,
status,
attempt,
maxAttempts: maxPollingAttempts,
elapsedMs,
nextRetryMs,
});
}
if (status === 'completed') {
if (response.result !== undefined) {
return response.result;
}
throw new Error(`Job ${jobId} completed but result is undefined`);
}
if (status === 'failed') {
throw new JobFailedError(jobId, response.error || 'Unknown error');
}
const retryAfterMs = (response.retryAfter || defaultRetryIntervalMs / 1000) * 1000;
// Use abortable sleep
await sleepWithAbort(retryAfterMs, signal);
}
throw new PollingTimeoutError(jobId || 'unknown', timeoutMs, attempt);
}
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does pollUntilComplete() do?
pollUntilComplete() is a function in the typescript-sdk codebase.
What does pollUntilComplete() call?
pollUntilComplete() calls 1 function(s): sleepWithAbort.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free