Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

ThrottleStrategy.md

110 lines2.3 KB

1---
2id: ThrottleStrategy
3title: ThrottleStrategy
4---
5​
6Defined in: [packages/db/src/strategies/types.ts:99](https://github.com/TanStack/db/blob/main/packages/db/src/strategies/types.ts#L99)
7​
8Throttle strategy that spaces executions evenly over time
9​
10## Extends
11​
12- [`BaseStrategy`](BaseStrategy.md)\<`"throttle"`\>
13​
14## Properties
15​
16### \_type
17​
18```ts
19_type: "throttle";
20```
21​
22Defined in: [packages/db/src/strategies/types.ts:8](https://github.com/TanStack/db/blob/main/packages/db/src/strategies/types.ts#L8)
23​
24Type discriminator for strategy identification
25​
26#### Inherited from
27​
28[`BaseStrategy`](BaseStrategy.md).[`_type`](BaseStrategy.md#_type)
29​
30***
31​
32### cleanup()
33​
34```ts
35cleanup: () => void;
36```
37​
38Defined in: [packages/db/src/strategies/types.ts:30](https://github.com/TanStack/db/blob/main/packages/db/src/strategies/types.ts#L30)
39​
40Clean up any resources held by the strategy
41Should be called when the strategy is no longer needed
42​
43#### Returns
44​
45`void`
46​
47#### Inherited from
48​
49[`BaseStrategy`](BaseStrategy.md).[`cleanup`](BaseStrategy.md#cleanup)
50​
51***
52​
53### execute()
54​
55```ts
56execute: <T>(fn, onAdmit?, onCommit?) => boolean | void | Promise<void>;
57```
58​
59Defined in: [packages/db/src/strategies/types.ts:20](https://github.com/TanStack/db/blob/main/packages/db/src/strategies/types.ts#L20)
60​
61Execute a function according to the strategy's timing rules
62​
63#### Type Parameters
64​
65##### T
66​
67`T` *extends* `object` = `Record`\<`string`, `unknown`\>
68​
69#### Parameters
70​
71##### fn
72​
73() => [`Transaction`](Transaction.md)\<`T`\>
74​
75The function to execute
76​
77##### onAdmit?
78​
79() => `void` \| [`Transaction`](Transaction.md)\<`T`\>
80​
81Optional synchronous preparation for an admitted call.
82Built-in debounce/throttle strategies call it after reserving the current
83edge but before invoking fn, and do not call it when returning false.
84​
85##### onCommit?
86​
87() => `Promise`\<`unknown`\> \| `undefined`
88​
89Optional promise for the actual commit attempt. It can
90outlive the public persistence receipt after a manual rollback.
91​
92#### Returns
93​
94`boolean` \| `void` \| `Promise`\<`void`\>
95​
96The result of the function execution (if applicable)
97​
98#### Inherited from
99​
100[`BaseStrategy`](BaseStrategy.md).[`execute`](BaseStrategy.md#execute)
101​
102***
103​
104### options
105​
106```ts
107options: ThrottleStrategyOptions;
108```
109​
110Defined in: [packages/db/src/strategies/types.ts:100](https://github.com/TanStack/db/blob/main/packages/db/src/strategies/types.ts#L100)