🔗File system watching
fswatch.nim exposes a FileWatcher that monitors a file or directory for changes, integrated with the event loop — no polling, no extra threads.
Runnable example: examples/fswatch.nim.
🔗Creating a watcher
let watcher = newFileWatcher(loop, "/tmp/powpow-test.txt", proc(w: FileWatcher; events: set[FileSystemEvent]) =
if fseModified in events:
echo "modified"
if fseDeleted in events:
echo "deleted"))The callback receives the watcher and the set of events that fired. FileSystemEvent values:
fseModified— contents changedfseCreated— file createdfseDeleted— file deletedfseRenamed— file renamedfseAttrib— attributes (permissions, times) changedfseLinkCount— hard-link count changedfseRevoke— access revoked
🔗Closing
watcher.close()🔗Backends
| Platform | Mechanism |
|---|---|
| macOS / BSD | kqueue EVFILT_VNODE |
| Linux | inotify |
| Windows | not yet implemented |
The watcher is owned by the loop: it registers its fd with the loop and is cleaned up via addCleanup when the loop closes.
🔗API reference
Full signatures: fswatch API.