Open History to see the last commit
1---
2id: RateLimiterOptions
3title: RateLimiterOptions
4---
5
6Defined in: [rate-limiter.ts:47](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/rate-limiter.ts#L47)
7
8Options for configuring a rate-limited function
9
10## Type Parameters
11
12### TFn
13
14`TFn` *extends* [`AnyFunction`](../type-aliases/AnyFunction.md)
15
16## Properties
17
18### enabled?
19
20```ts
21optional enabled?: boolean | ((rateLimiter) => boolean);
22```
23
24Defined in: [rate-limiter.ts:52](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/rate-limiter.ts#L52)
25
26Whether the rate limiter is enabled. When disabled, maybeExecute will not trigger any executions.
27Defaults to true.
28
29***
30
31### initialState?
32
33```ts
34optional initialState?: Partial<RateLimiterState>;
35```
36
37Defined in: [rate-limiter.ts:56](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/rate-limiter.ts#L56)
38
39Initial state for the rate limiter
40
41***
42
43### key?
44
45```ts
46optional key?: string;
47```
48
49Defined in: [rate-limiter.ts:61](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/rate-limiter.ts#L61)
50
51Optional key to identify this rate limiter instance.
52If provided, the rate limiter will be identified by this key in the devtools and PacerProvider if applicable.
53
54***
55
56### limit
57
58```ts
59limit: number | ((rateLimiter) => number);
60```
61
62Defined in: [rate-limiter.ts:66](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/rate-limiter.ts#L66)
63
64Maximum number of executions allowed within the time window.
65Can be a number or a callback function that receives the rate limiter instance and returns a number.
66
67***
68
69### onExecute?
70
71```ts
72optional onExecute?: (args, rateLimiter) => void;
73```
74
75Defined in: [rate-limiter.ts:70](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/rate-limiter.ts#L70)
76
77Callback function that is called after the function is executed
78
79#### Parameters
80
81##### args
82
83`Parameters`\<`TFn`\>
84
85##### rateLimiter
86
87[`RateLimiter`](../classes/RateLimiter.md)\<`TFn`\>
88
89#### Returns
90
91`void`
92
93***
94
95### onReject?
96
97```ts
98optional onReject?: (rateLimiter) => void;
99```
100
101Defined in: [rate-limiter.ts:74](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/rate-limiter.ts#L74)
102
103Optional callback function that is called when an execution is rejected due to rate limiting
104
105#### Parameters
106
107##### rateLimiter
108
109[`RateLimiter`](../classes/RateLimiter.md)\<`TFn`\>
110
111#### Returns
112
113`void`
114
115***
116
117### window
118
119```ts
120window: number | ((rateLimiter) => number);
121```
122
123Defined in: [rate-limiter.ts:79](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/rate-limiter.ts#L79)
124
125Time window in milliseconds within which the limit applies.
126Can be a number or a callback function that receives the rate limiter instance and returns a number.
127
128***
129
130### windowType?
131
132```ts
133optional windowType?: "fixed" | "sliding";
134```
135
136Defined in: [rate-limiter.ts:86](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/rate-limiter.ts#L86)
137
138Type of window to use for rate limiting
139- 'fixed': Uses a fixed window that resets after the window period
140- 'sliding': Uses a sliding window that allows executions as old ones expire
141Defaults to 'fixed'