p-ratelimit-jg
Version:
Promise-based utility to make sure you don’t call rate-limited APIs too quickly.
24 lines (23 loc) • 856 B
TypeScript
import { Dequeue } from '../dequeue';
import { Quota } from './quota';
/** keep track of API invocations, allowing or disallowing them based on our quota */
export declare class QuotaManager {
protected _quota: Quota;
protected _activeCount: number;
protected history: Dequeue<unknown>;
constructor(_quota: Quota);
/** The current quota */
get quota(): Quota;
/** The number of currently-active invocations */
get activeCount(): number;
/** Max amount of time a queued request can wait before throwing a timeout error */
get maxDelay(): number;
/**
* Log that an invocation started.
* @returns true if the invocation was allowed, false if not (you can try again later)
*/
start(): boolean;
/** Log that an invocation ended */
end(): void;
protected removeExpiredHistory(): void;
}