Alpha. Vary is under active development and not ready for production use. Syntax, APIs, performance, and behaviour may change between releases.

File Watching

Monitor filesystem changes with debouncing and glob-based ignore patterns:

import fs

let watcher = fs.watch("./src")
mut changes = watcher.next_batch()
while changes is not None {
    for c in changes {
        print(f"{c.kind()} {c.path()}")
    }
    changes = watcher.next_batch()
}
FunctionReturnsDescription
fs.watch(directory, recursive?, settle_ms?, ignore?)FileWatcherCreate a persistent file watcher
fs.watch_once(directory)List[FileChange]Wait for a single batch of changes

Defaults: recursive=True, settle_ms=100, ignore=[".git/", ".DS_Store", "*.swp", "*.swo", "*~", "#*#", ".#*"].

FileWatcher methods:

MethodReturnsDescription
.next_batch(timeout_ms?)List[FileChange]Wait for next batch of changes (None = block forever)
.close()NoneStop watching
.is_closed()BoolCheck if watcher is closed

FileChange methods:

MethodReturnsDescription
.kind()Str"created", "modified", "deleted", "overflow"
.path()StrPath relative to watch root
.absolute_path()StrAbsolute filesystem path
.is_dir()BoolTrue if the changed path is a directory