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