We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
private async withRetry<T>( operation: () => Promise<T>, retries = 3, delay = 1000 ): Promise<T> { try { return await operation(); } catch (error) { if (retries > 0) { await new Promise(resolve => setTimeout(resolve, delay)); return this.withRetry(operation, retries - 1, delay * 2); } throw error; } }
class RateLimiter { private queue: Array<() => Promise<void>> = []; private processing = false; constructor(private rateLimit: number, private interval: number) {} async schedule<T>(task: () => Promise<T>): Promise<T> { return new Promise((resolve, reject) => { this.queue.push(async () => { try { resolve(await task()); } catch (error) { reject(error); } }); this.process(); }); } private async process(): Promise<void> { if (this.processing) return; this.processing = true; while (this.queue.length > 0) { const batch = this.queue.splice(0, this.rateLimit); await Promise.all(batch.map(task => task())); await new Promise(resolve => setTimeout(resolve, this.interval)); } this.processing = false; } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: