Open History to see the last commit
1---
2id: createQueuer
3title: createQueuer
4---
5
6```ts
7function createQueuer<TValue, TSelected>(
8 host,
9 fn,
10 options?,
11selector?): LitQueuer<TValue, TSelected>;
12```
13
14Defined in: [queuer/createQueuer.ts:89](https://github.com/TanStack/pacer/blob/main/packages/lit-pacer/src/queuer/createQueuer.ts#L89)
15
16Creates and retains the Queuer for its Lit owner.
17
18Retains items until they are processed. Use addItem to enqueue work and start, stop, execute, clear, or flush to control processing. Selected state exposes pending items, capacity, and completed work.
19
20## State and subscriptions
21
22Pass a selector to track only the state consumed by the owner. The default selection is {},
23so utility state changes do not update the owner unless it opts in. Selection uses shallow
24comparison. The raw store remains available for additional subscriptions.
25Use utility.subscribe(childHost, selector) for a child subscription. It returns a getter
26and cleans up with the child without canceling the parent utility.
27
28Available state fields:
29
30- `addItemCount`: Number of times addItem has been called (for reduction calculations)
31- `executionCount`: Number of items that have been processed by the queuer
32- `expirationCount`: Number of items that have been removed from the queue due to expiration
33- `isEmpty`: Whether the queuer has no items to process (items array is empty)
34- `isFull`: Whether the queuer has reached its maximum capacity
35- `isIdle`: Whether the queuer is not currently processing any items
36- `isRunning`: Whether the queuer is active and will process items automatically
37- `items`: Array of items currently waiting to be processed
38- `itemTimestamps`: Timestamps when items were added to the queue for expiration tracking
39- `pendingTick`: Whether the queuer has a pending timeout for processing the next item
40- `rejectionCount`: Number of items that have been rejected from being added to the queue
41- `size`: Number of items currently in the queue
42- `status`: Current processing status - 'idle' when not processing, 'running' when active, 'stopped' when paused
43
44## Options and ownership
45
46Pass an options object with property getters or a factory. Top-level properties are read
47reactively; function-valued core options remain callbacks. Local options override provider
48defaults. Updates retain the utility, its store, counters, and pending work.
49Disconnecting the host calls stop().
50onUnmount replaces default cleanup and receives the same adapter instance. A custom callback
51must perform all required cleanup. Use flush() where supported to finish pending work.
52Reconnecting the host refreshes options and restores subscriptions to the same instance.
53
54## Type Parameters
55
56### TValue
57
58`TValue`
59
60### TSelected
61
62`TSelected` = \{
63\}
64
65## Parameters
66
67### host
68
69`ReactiveControllerHost`
70
71Owner of option updates, subscriptions, and cleanup.
72
73### fn
74
75(`item`) => `void`
76
77Function executed by the utility.
78
79### options?
80
81[`LitPacerOptions`](../type-aliases/LitPacerOptions.md)\<[`LitQueuerOptions`](../interfaces/LitQueuerOptions.md)\<`TValue`, `TSelected`\>\> = `{}`
82
83Core options or a reactive factory, plus an optional onUnmount callback.
84
85### selector?
86
87(`state`) => `TSelected`
88
89Selects state that updates the owner. Omit to leave selected state empty.
90
91## Returns
92
93[`LitQueuer`](../interfaces/LitQueuer.md)\<`TValue`, `TSelected`\>
94
95The retained utility instance with selected state and child subscriptions.
96
97## Example
98
99```ts
100import { createQueuer } from '@tanstack/lit-pacer'
101
102const utility = createQueuer(
103 this, (value: string) => { console.log(value) },
104 { wait: 100 },
105 (state) => ({ size: state.size }),
106)
107utility.addItem('item')
108// Selected state: utility.state.size
109```