Skip to content

Commit 0592852

Browse files
KyleAMathewsclaude
andauthored
Upgrade pacer package (#829)
* Upgrade @tanstack/pacer to v0.16.2 and fix AsyncQueuer API usage The pacer package API changed significantly from v0.1.0 to v0.16.2: - AsyncQueuer constructor now takes the function as first parameter - Items are passed to addItem() instead of functions being passed to addItem() - Updated queueStrategy to use new API pattern This fixes the build errors in packages/db/src/strategies/queueStrategy.ts * Improve type safety in queueStrategy by avoiding 'any' Replace Transaction<any> with Transaction to match the pattern used in debounceStrategy and throttleStrategy. This maintains type safety while allowing the queuer to handle transactions with different generic types. - Changed AsyncQueuer<() => Transaction<any>> to AsyncQueuer<() => Transaction> - Added type cast in addItem call: fn as () => Transaction - Consistent with existing strategy implementations --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3ce0264 commit 0592852

File tree

3 files changed

+39
-22
lines changed

3 files changed

+39
-22
lines changed

packages/db/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"dependencies": {
66
"@standard-schema/spec": "^1.0.0",
77
"@tanstack/db-ivm": "workspace:*",
8-
"@tanstack/pacer": "^0.1.0"
8+
"@tanstack/pacer": "^0.16.2"
99
},
1010
"devDependencies": {
1111
"@vitest/coverage-istanbul": "^3.2.4",

packages/db/src/strategies/queueStrategy.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,31 @@ import type { Transaction } from "../transactions"
4444
* ```
4545
*/
4646
export function queueStrategy(options?: QueueStrategyOptions): QueueStrategy {
47-
const queuer = new AsyncQueuer<void>({
48-
concurrency: 1, // Process one at a time to ensure serialization
49-
wait: options?.wait,
50-
maxSize: options?.maxSize,
51-
addItemsTo: options?.addItemsTo ?? `back`, // Default FIFO: add to back
52-
getItemsFrom: options?.getItemsFrom ?? `front`, // Default FIFO: get from front
53-
started: true, // Start processing immediately
54-
})
47+
const queuer = new AsyncQueuer<() => Transaction>(
48+
async (fn) => {
49+
const transaction = fn()
50+
// Wait for the transaction to be persisted before processing next item
51+
// Note: fn() already calls commit(), we just wait for it to complete
52+
await transaction.isPersisted.promise
53+
},
54+
{
55+
concurrency: 1, // Process one at a time to ensure serialization
56+
wait: options?.wait,
57+
maxSize: options?.maxSize,
58+
addItemsTo: options?.addItemsTo ?? `back`, // Default FIFO: add to back
59+
getItemsFrom: options?.getItemsFrom ?? `front`, // Default FIFO: get from front
60+
started: true, // Start processing immediately
61+
}
62+
)
5563

5664
return {
5765
_type: `queue`,
5866
options,
5967
execute: <T extends object = Record<string, unknown>>(
6068
fn: () => Transaction<T>
6169
) => {
62-
// Wrap the callback in an async function that waits for persistence
63-
queuer.addItem(async () => {
64-
const transaction = fn()
65-
// Wait for the transaction to be persisted before processing next item
66-
// Note: fn() already calls commit(), we just wait for it to complete
67-
await transaction.isPersisted.promise
68-
})
70+
// Add the transaction-creating function to the queue
71+
queuer.addItem(fn as () => Transaction)
6972
},
7073
cleanup: () => {
7174
queuer.stop()

pnpm-lock.yaml

Lines changed: 20 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)