mirror of
https://github.com/johndoe6345789/low-code-react-app-b.git
synced 2026-04-24 13:44:54 +00:00
Merge pull request #185 from johndoe6345789/codex/update-persistencequeue-for-proper-flushing
Fix persistence queue flush ordering
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user