Files
orca/src/main/ipc/filesystem-watcher-batch-control.ts
T
Jinjing 50938b2dbd Serialize filesystem watcher batch flush operations (#17602)
* Serialize filesystem watcher batch flush operations

- Prevent dropped events during rapid concurrent file changes
- Queue and drain follow-up batches to preserve event ordering
- Cancel pending batch work when watchers are torn down

* Prevent queued batch drain while debounce timer is armed

An armed timer means the debounce window is still open. Drain only after
the window closes to avoid splitting related filesystem events across
separate payloads.

* Remove redundant batch timer cleanup

Rely on cancelLocalBatchFlush to handle the batch timer
teardown, eliminating duplicate logic in the watcher
cleanup path.
2026-08-31 18:28:26 -07:00

38 lines
944 B
TypeScript

import type { Event as WatcherEvent } from '@parcel/watcher'
import type { WatchedRoot } from './filesystem-watcher-wsl'
export type DebouncedBatch = {
events: WatcherEvent[]
overflowed: boolean
timer: ReturnType<typeof setTimeout> | null
firstEventAt: number
flushInFlight: boolean
flushQueued: boolean
cancelled: boolean
}
export function createDebouncedBatch(): DebouncedBatch {
return {
events: [],
overflowed: false,
timer: null,
firstEventAt: 0,
flushInFlight: false,
flushQueued: false,
cancelled: false
}
}
/** Cancel pending and queued flush work when a root is torn down. */
export function cancelLocalBatchFlush(root: WatchedRoot): void {
root.batch.cancelled = true
root.batch.flushQueued = false
if (root.batch.timer) {
clearTimeout(root.batch.timer)
root.batch.timer = null
}
root.batch.events = []
root.batch.overflowed = false
root.batch.firstEventAt = 0
}