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

queueStrategy.md

67 lines1.8 KB

1---
2id: queueStrategy
3title: queueStrategy
4---
5​
6```ts
7function queueStrategy(options?): QueueStrategy;
8```
9​
10Defined in: [packages/db/src/strategies/queueStrategy.ts:52](https://github.com/TanStack/db/blob/main/packages/db/src/strategies/queueStrategy.ts#L52)
11​
12Creates a queue strategy that processes all mutations in order with proper serialization.
13​
14Unlike other strategies that may drop executions, queue ensures every
15mutation is attempted sequentially. Each transaction commit completes before
16the next one starts. Useful when data consistency is critical and
17every operation must be attempted in order.
18​
19**Error handling behavior:**
20- If a mutation fails, it is NOT automatically retried - the transaction transitions to "failed" state
21- Failed mutations surface their error via `transaction.isPersisted.promise` (which will reject)
22- Subsequent mutations continue processing - a single failure does not block the queue
23- Each mutation is independent; there is no all-or-nothing transaction semantics
24​
25## Parameters
26​
27### options?
28​
29[`QueueStrategyOptions`](../interfaces/QueueStrategyOptions.md)
30​
31Configuration for queue behavior (FIFO/LIFO, timing, size limits)
32​
33## Returns
34​
35[`QueueStrategy`](../interfaces/QueueStrategy.md)
36​
37A queue strategy instance
38​
39## Examples
40​
41```ts
42// FIFO queue - process in order received
43const mutate = usePacedMutations({
44 mutationFn: async ({ transaction }) => {
45 await api.save(transaction.mutations)
46 },
47 strategy: queueStrategy({
48 wait: 200,
49 addItemsTo: 'back',
50 getItemsFrom: 'front'
51 })
52})
53```
54​
55```ts
56// LIFO queue - process most recent first
57const mutate = usePacedMutations({
58 mutationFn: async ({ transaction }) => {
59 await api.save(transaction.mutations)
60 },
61 strategy: queueStrategy({
62 wait: 200,
63 addItemsTo: 'back',
64 getItemsFrom: 'back'
65 })
66})
67```