https://github.com/ttytm/dmon-zig
I use it on a small server to hande interactions of some network devices.
Simple example:
const std = @import("std");
const dmon = @import("dmon");
const print = std.debug.print;
const Context = struct {
triggerCount: u32 = 0,
};
pub fn watchCb(
comptime Ctx: type,
_: dmon.WatchId,
action: dmon.Action,
_: [*:0]const u8,
file_path: [*:0]const u8,
old_file_path: ?[*:0]const u8,
context: *Ctx,
) void {
print("Action: {}\n", .{action});
print("File path: {s}\n", .{file_path});
print("Old file path: {s}\n", .{old_file_path orelse ""});
context.triggerCount += 1;
}
pub fn main() !void {
dmon.init();
defer dmon.deinit();
const watch_path = "/home/user/Documents";
const id = dmon.watch(Context, watch_path, watchCb, .{ .recursive = true }, &ctx);
print("Starting to watch: {s}; Watcher ID: {d}\n", .{ watch_path, id });
while (true) {
if (ctx.triggerCount >= 3) break;
}
}