Available
amalgame-io-filewatcher
inotify on Linux, polling elsewhere.
Overview
Watches a file or a directory, to reload a config or rerun a build. On Linux, inotify reports changes within milliseconds (since v0.4). Elsewhere, each Poll() compares mtimes. The same API works in both cases. FSEvents (macOS) and ReadDirectoryChangesW (Windows) are planned for v0.6.
Features
- ✓Recursive or shallow watching
- ✓Typed events:
Created,Modified,Deleted,Renamed;Renamedgives the old and the new path (inotify, v0.5) - ✓
Poll()returns the events since the previous call: you choose the pace - ✓Editors' atomic saves (write then rename) are handled: the file stays watched
- ✓Cross-OS — no exotic system dep
Example
Minimal usage example — copy-paste runnable after install.
amc package add io-filewatcher datetime
import Amalgame.IO.FileWatcher
import Amalgame.DateTime
class Program {
public static void Main() {
let w = new DirectoryWatcher("./src", true) // recursive
Console.WriteLine("backend: " + w.BackendName()) // "inotify" on Linux
while (true) {
let events: List<WatchEvent> = w.Poll()
for ev in events {
if (ev.KindOf() == WatchEventKind.Renamed) {
Console.WriteLine("renamed: " + ev.PathOf() + " -> " + ev.RenamedToOf())
} else {
Console.WriteLine("changed: " + ev.PathOf())
}
}
DateTime.SleepMillis(250)
}
}
}
At a glance
- License: Apache-2.0
- Install:
amc package add io-filewatcher - Source: amalgame-lang/amalgame-io-filewatcher
- Official index: amalgame-lang/packages-index