Merge pull request #185 from johndoe6345789/codex/update-persistencequeue-for-proper-flushing

Fix persistence queue flush ordering
This commit is contained in:
2026-01-18 18:19:11 +00:00
committed by GitHub

View File

@@ -41,6 +41,7 @@ type PendingOperation = {
class PersistenceQueue {
private queue: Map<string, PendingOperation> = new Map()
private processing = false
private pendingFlush = false
private debounceTimers: Map<string, ReturnType<typeof setTimeout>> = new Map()
enqueue(operation: PendingOperation, debounceMs: number) {
@@ -62,7 +63,12 @@ class PersistenceQueue {
}
async processQueue() {
if (this.processing || this.queue.size === 0) return
if (this.processing) {
this.pendingFlush = true
return
}
if (this.queue.size === 0) return
this.processing = true
@@ -97,6 +103,11 @@ class PersistenceQueue {
}
} finally {
this.processing = false
const needsFlush = this.pendingFlush || this.queue.size > 0
this.pendingFlush = false
if (needsFlush) {
await this.processQueue()
}
}
}