class

FSWatch::Inotify

Inherits FSWatch::Backend < Reference < Object

Constants

IN_ATTRIB = 4_u32
IN_CLOEXEC = 524288
IN_CREATE = 256_u32
IN_DELETE = 512_u32
IN_DELETE_SELF = 1024_u32
IN_IGNORED = 32768_u32
IN_ISDIR = 1073741824_u32
IN_MODIFY = 2_u32

Event masks (inotify(7)).

IN_MOVE_SELF = 2048_u32
IN_MOVED_FROM = 64_u32
IN_MOVED_TO = 128_u32
IN_NONBLOCK = 2048
IN_Q_OVERFLOW = 16384_u32
STOP_CADENCE = 0.5.seconds

How often the read loop re-checks @stopped: the evented read carries a read_timeout so a stopped backend still exits promptly instead of sleeping until the next event.

WATCH_MASK = ((((((IN_MODIFY | IN_ATTRIB) | IN_MOVED_FROM) | IN_MOVED_TO) | IN_CREATE) | IN_DELETE) | IN_DELETE_SELF) | IN_MOVE_SELF
YIELD_EVERY = 64

Directories the descent arms between Fiber.yields: the walk must share the scheduler, but each yield is also the only point a concurrent #stop can land — the stop-check after every yield is what keeps arming from racing the fd teardown.

Constructors

new(recursive : Bool, interval : Time::Span | Nil = nil, skip : String -> Bool | Nil = nil, &emit : Event -> )
Source

Instance methods

add(path : String) : Nil

Begin watching path (a file or a directory). With recursive set at construction, backends extend the watch to the tree — natively where the API allows (inotify: add a watch per directory on create; kqueue: rescan on directory NOTE_WRITE; poll: the tree walk is the watch).

Source
remove(path : String) : Nil

Stop watching path (and, for directories, its subtree).

Source
run

The observation loop — runs INSIDE a fiber spawned by the core; returns when stopped. Must never block the scheduler thread: waits go through the event loop (evented IO / sleep / select).

Source
stop

Request teardown; must be callable from any fiber. The run loop may take a bounded moment (stop-check cadence) to actually exit.

Source