@geoapify/request-rate-limiter
Version:
Easily throttle API requests to prevent 429 errors and manage traffic bursts
30 lines • 1.15 kB
TypeScript
import { RequestFunction, Options } from './types';
/**
* Execute a list of requests with rate limiting
*
* @template T The type of data returned by each request
* @param requests Array of functions that return promises or values
* @param maxRequests Maximum number of requests to execute within the interval
* @param interval Time interval in milliseconds
* @param options Optional configuration for progress tracking and batch processing
* @returns Promise that resolves to an array of results
*
* @example
* ```typescript
* const requests = [
* () => fetch('https://api.example.com/1'),
* () => fetch('https://api.example.com/2'),
* () => fetch('https://api.example.com/3')
* ];
*
* const results = await rateLimitedRequests(requests, 5, 1000);
* ```
*/
declare function rateLimitedRequests<T = any>(requests: RequestFunction<T>[], maxRequests: number, interval: number, options?: Options<T>): Promise<T[]>;
export { rateLimitedRequests };
export * from './types';
declare const _default: {
rateLimitedRequests: typeof rateLimitedRequests;
};
export default _default;
//# sourceMappingURL=request-rate-limiter.d.ts.map