OptionalonRetryFailed: (error: Error) => voidOptional callback invoked if retries are exhausted after transient errors.
Promise that resolves when rate limit permits the request.
export async function acquireRateLimit(
onRetryFailed?: (error: Error) => void,
): Promise<void> {
return new Promise<void>((resolve) => {
// Queue this request with initial retry tracking
requestQueue.push({
resolve,
attempt: 0,
maxAttempts: MAX_RETRIES,
nextEligibleAt: Date.now(),
onRetryFailed,
});
// Start processing if not already active
if (!isProcessingQueue()) {
processRateLimitQueue();
}
});
}
Acquire a rate limit slot for making a request.
Queues the request and starts the processor if inactive. Blocks until it's safe to make the request based on rate limit intervals.