UNPKG

953 BTypeScriptView Raw
1import { AxiosInstance } from "axios";
2export interface IRequestLimiterCallback {
3 (axiosClient: AxiosInstance): Promise<any>;
4}
5export default class RequestLimiter {
6 private max_requests;
7 private interval;
8 private axiosClient;
9 private requests;
10 private lastRequest;
11 private timer;
12 private queue;
13 constructor(max_requests: number, interval: number, axiosClient: AxiosInstance | false);
14 /**
15 * Wrap the callable given by the user and wrap it in a promise
16 * @param callable
17 * @returns {Promise<any>}
18 */
19 private wrapCallable;
20 /**
21 * Check if a new item from the queue should be called
22 */
23 private check;
24 /**
25 * Start the timer which updates and resets the limits
26 */
27 private setTimer;
28 /**
29 * Clear the timer
30 */
31 private clearTimer;
32 /**
33 * Run the request limit checker
34 * @param callable
35 * @returns {any}
36 */
37 run: any;
38}