Download packages/coding-agent/src/utils/fs-watch.ts from SaylorTwift/pi: direct link, hf CLI and curl.
- Browser
- Download file 573 Bytes
-
https://huggingface.co/SaylorTwift/pi/resolve/main/packages/coding-agent/src/utils/fs-watch.ts
- Command line
-
hf download hf://SaylorTwift/pi/packages/coding-agent/src/utils/fs-watch.ts
-
curl -L -o fs-watch.ts https://huggingface.co/SaylorTwift/pi/resolve/main/packages/coding-agent/src/utils/fs-watch.ts
573 Bytes
| import { type FSWatcher, type WatchListener, watch } from "node:fs"; | |
| export const FS_WATCH_RETRY_DELAY_MS = 5000; | |
| export function closeWatcher(watcher: FSWatcher | null | undefined): void { | |
| if (!watcher) { | |
| return; | |
| } | |
| try { | |
| watcher.close(); | |
| } catch { | |
| // Ignore watcher close errors | |
| } | |
| } | |
| export function watchWithErrorHandler( | |
| path: string, | |
| listener: WatchListener<string>, | |
| onError: () => void, | |
| ): FSWatcher | null { | |
| try { | |
| const watcher = watch(path, listener); | |
| watcher.on("error", onError); | |
| return watcher; | |
| } catch { | |
| onError(); | |
| return null; | |
| } | |
| } | |