Last updated

🔗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 changed
  • fseCreated — file created
  • fseDeleted — file deleted
  • fseRenamed — file renamed
  • fseAttrib — attributes (permissions, times) changed
  • fseLinkCount — hard-link count changed
  • fseRevoke — access revoked

🔗Closing

watcher.close()

🔗Backends

PlatformMechanism
macOS / BSDkqueue EVFILT_VNODE
Linuxinotify
Windowsnot 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.