Stops the watcher and disconnects all signal handlers.
@eryx/fs_watch Module
JSON
Filesystem watcher with Signal-based event delivery.
Watch a single file:
local fsWatch = require("@eryx/fs_watch")
local watcher = fsWatch.watchFile("config.json")
watcher.changed:connect(function(eventType)
print("config.json:", eventType) -- "change" or "rename"
end)
-- later:
watcher:stop()
Watch a directory (with debounce to coalesce rapid OS events):
local watcher = fsWatch.watchDir("src/", { recursive = true, debounce = 0.1 })
watcher.changed:connect(function(filename, eventType)
print(filename, eventType)
end)
watcher:stop()
Summary
Classes
Functions
API Reference
Classes
FileWatcher
Properties
Fires when the watched file changes.
Receives (eventType) where eventType is "change" or "rename".
FileWatcher:stop
FileWatcher:ref
Makes this watcher keep the event loop alive (watchers are unref'd by default).
FileWatcher:unref
Allows the event loop to exit while this watcher is active (the default).
DirWatcher
Properties
Fires when any file in the watched directory changes.
Receives (filename, eventType). filename is the path of the
changed file relative to the watched directory.
DirWatcher:stop
Stops the watcher and disconnects all signal handlers.
DirWatcher:ref
Makes this watcher keep the event loop alive (watchers are unref'd by default).
DirWatcher:unref
Allows the event loop to exit while this watcher is active (the default).
Functions
fs_watch.watchFile
Watches a single file for changes.
Returns a FileWatcher whose changed signal fires with (eventType).
fs_watch.watchDir
Watches a directory for changes.
Returns a DirWatcher whose changed signal fires with (filename, eventType).
Types
WatchOptions
Watch subdirectories recursively (supported on Windows and macOS; on Linux you may need individual watchers per subdirectory).
Debounce interval in seconds. When set, rapid-fire OS events for the
same file are coalesced - only the last event fires after the interval
elapses with no new events. Set to 0 or nil to disable.