Open History to see the last commit
1---
2id: createAsyncQueuedState
3title: createAsyncQueuedState
4---
5
6```ts
7function createAsyncQueuedState<TValue, TSelected>(
8 host,
9 fn,
10 options?,
11 selector?): [() => TValue[], LitAsyncQueuer<TValue, TSelected>];
12```
13
14Defined in: [async-queuer/createAsyncQueuedState.ts:35](https://github.com/TanStack/pacer/blob/main/packages/lit-pacer/src/async-queuer/createAsyncQueuedState.ts#L35)
15
16Exposes pending queue items together with the queue that processes them.
17
18Retains accepted items until processing. Ordering, capacity, wait, and started options follow the underlying queue.
19
20## Return value
21
22Returns [itemsAccessor, queue]. Call itemsAccessor() to read pending items. Call queue.addItem() to enqueue; there is no separate setter tuple entry.
23
24## State and ownership
25
26Items are selected by default. A custom selector must retain items and may add other state fields. The returned collection contains pending items; async active items are separate.
27
28Pass the owning ReactiveControllerHost first. Host updates refresh options. Disconnecting runs cleanup; reconnecting restores subscriptions to the same utility.
29Options accept an object with top-level getters or an options factory. Function-valued core options remain callbacks. Local options override provider defaults without replacing the utility or its pending work.
30onUnmount replaces default cleanup and receives the utility instance. A custom callback must perform every needed cancel, stop, or abort action.
31
32## Type Parameters
33
34### TValue
35
36`TValue`
37
38### TSelected
39
40`TSelected` *extends* `Pick`\<`AsyncQueuerState`\<`TValue`\>, `"items"`\> = `Pick`\<`AsyncQueuerState`\<`TValue`\>, `"items"`\>
41
42## Parameters
43
44### host
45
46`ReactiveControllerHost`
47
48### fn
49
50(`item`) => `Promise`\<`any`\>
51
52### options?
53
54[`LitPacerOptions`](../type-aliases/LitPacerOptions.md)\<[`LitAsyncQueuerOptions`](../interfaces/LitAsyncQueuerOptions.md)\<`TValue`, `TSelected`\>\> = `{}`
55
56### selector?
57
58(`state`) => `TSelected`
59
60## Returns
61
62\[() => `TValue`[], [`LitAsyncQueuer`](../interfaces/LitAsyncQueuer.md)\<`TValue`, `TSelected`\>\]
63
64## Example
65
66```ts
67import { createAsyncQueuedState } from '@tanstack/lit-pacer'
68
69// In a LitElement constructor:
70const [items, queue] = createAsyncQueuedState(this, async (item: number) => { console.log(item) }, { wait: 500 })
71queue.addItem(1)
72console.log(items())
73```
74
75## See
76
77createAsyncQueuer