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

useAsyncQueuedState.md

72 lines2.2 KB

1---
2id: useAsyncQueuedState
3title: useAsyncQueuedState
4---
5​
6```ts
7function useAsyncQueuedState<TValue, TSelected>(
8 fn,
9 options?,
10 selector?): [() => TValue[], VueAsyncQueuer<TValue, TSelected>];
11```
12​
13Defined in: [async-queuer/useAsyncQueuedState.ts:34](https://github.com/TanStack/pacer/blob/main/packages/vue-pacer/src/async-queuer/useAsyncQueuedState.ts#L34)
14​
15Exposes pending queue items together with the queue that processes them.
16​
17Retains accepted items until processing. Ordering, capacity, wait, and started options follow the underlying queue.
18​
19## Return value
20​
21Returns [itemsAccessor, queue]. Call itemsAccessor() to read pending items. Call queue.addItem() to enqueue; there is no separate setter tuple entry.
22​
23## State and ownership
24​
25Items 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.
26​
27Call during component setup or in an active effect scope. Scope disposal removes watchers and subscriptions and runs utility cleanup.
28Options 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.
29onUnmount replaces default cleanup and receives the utility instance. A custom callback must perform every needed cancel, stop, or abort action.
30​
31## Type Parameters
32​
33### TValue
34​
35`TValue`
36​
37### TSelected
38​
39`TSelected` *extends* `Pick`\<`AsyncQueuerState`\<`TValue`\>, `"items"`\> = `Pick`\<`AsyncQueuerState`\<`TValue`\>, `"items"`\>
40​
41## Parameters
42​
43### fn
44​
45(`item`) => `Promise`\<`any`\>
46​
47### options?
48​
49[`VuePacerOptions`](../type-aliases/VuePacerOptions.md)\<[`VueAsyncQueuerOptions`](../interfaces/VueAsyncQueuerOptions.md)\<`TValue`, `TSelected`\>\> = `{}`
50​
51### selector?
52​
53(`state`) => `TSelected`
54​
55## Returns
56​
57\[() => `TValue`[], [`VueAsyncQueuer`](../interfaces/VueAsyncQueuer.md)\<`TValue`, `TSelected`\>\]
58​
59## Example
60​
61```ts
62import { useAsyncQueuedState } from '@tanstack/vue-pacer'
63​
64// During component setup:
65const [items, queue] = useAsyncQueuedState(async (item: number) => { console.log(item) }, { wait: 500 })
66queue.addItem(1)
67console.log(items())
68```
69​
70## See
71​
72useAsyncQueuer