import { EventEmitter } from "events"; export default class RequestRateLimiter { backoffTime: number; private requestRate; private interval; private timeout; bucket: any; private requestHandler; private _eventEmitter; /** * The constructor accepts 4 additional options, which can be used to configure the behaviour of the limiter: * backoffTime: how many seconds to back off when the remote end indicates to back off * requestRate: how many requests can be sent within the interval * interval: the interval within which all requests of the requestRate should be executed * timeout: no request will stay in the queue any longer than the timeout. if the queue is full, the requst will be rejected * */ constructor(_eventEmitter: EventEmitter, { backoffTime, requestRate, interval, timeout, }?: { backoffTime?: number; requestRate?: number; interval?: number; timeout?: number; }); /** * promise that resolves when the rate limited becomes idle * once resolved, the call to this method must be repeated * in order to become notified again. */ idle(): Promise; /** * enqueue a request */ request(requestConfig: any): Promise; /** * actually execute the requests */ executeRequest(requestConfig: any): Promise; /** * set the reuqest handler that shall be used to handle the requests */ setRequestHandler(requestHandler: any): void; }