@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
33 lines • 964 B
JavaScript
// fs.watch misses events under rename-heavy writers, so file monitors poll. A paused watch
// clears its timer entirely (zero wakeups, zero stat/digest work) and resume() runs one
// immediate check, so a change made during the pause is still detected and fired.
export const FILE_MONITOR_POLL_MS = 250;
export class FileWatchLoop {
#check;
#timer;
#stopped = false;
constructor(check) {
this.#check = check;
this.#start();
}
pause() {
if (this.#timer === undefined)
return;
clearInterval(this.#timer);
this.#timer = undefined;
}
resume() {
if (this.#stopped || this.#timer !== undefined)
return;
this.#start();
this.#check();
}
stop() {
this.#stopped = true;
this.pause();
}
#start() {
this.#timer = setInterval(this.#check, FILE_MONITOR_POLL_MS);
}
}
//# sourceMappingURL=monitor-file-watch.js.map