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