diff --git a/README.md b/README.md index 9b5e233..d01015d 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ The Watch is written in **Zig** and built using the Zig build system. ## Requirements -- Zig (currently zig-0.15.2) +- Zig - zig-0.16.0-dev (master branch) or zig-0.15.2 (zig-0.15 branch) ## Build CLI @@ -145,11 +145,13 @@ const H = struct { } }; -var h = H{ .handler = .{ .vtable = &H.vtable } }; -var watcher = try nightwatch.Default.init(allocator, &h.handler); -defer watcher.deinit(); -try watcher.watch("/path/to/dir"); -// watcher delivers events on a background thread until deinit() +pub fn main(init: std.process.Init) !void { + var h = H{ .handler = .{ .vtable = &H.vtable } }; + var watcher = try nightwatch.Default.init(init.io, init.gpa, &h.handler); + defer watcher.deinit(); + try watcher.watch("/path/to/dir"); + // watcher delivers events on a background thread until deinit() +} ``` See the [`examples/`](examples/) directory for complete, buildable programs. diff --git a/examples/simple-default.zig b/examples/simple-default.zig index a04bf87..24ee823 100644 --- a/examples/simple-default.zig +++ b/examples/simple-default.zig @@ -23,11 +23,10 @@ const H = struct { } }; -pub fn main() !void { - const allocator = std.heap.page_allocator; +pub fn main(init: std.process.Init) !void { var h = H{ .handler = .{ .vtable = &H.vtable } }; - var watcher = try nightwatch.Default.init(allocator, &h.handler); + var watcher = try nightwatch.Default.init(init.io, init.gpa, &h.handler); defer watcher.deinit(); try watcher.watch("."); - std.Thread.sleep(std.time.ns_per_s * 60); + std.Io.sleep(init.io, std.Io.Duration.fromMilliseconds(60_000), .awake) catch {}; } diff --git a/examples/simple-polling.zig b/examples/simple-polling.zig index d797b53..15df2da 100644 --- a/examples/simple-polling.zig +++ b/examples/simple-polling.zig @@ -38,10 +38,9 @@ const H = struct { } }; -pub fn main() !void { - const allocator = std.heap.page_allocator; +pub fn main(init: std.process.Init) !void { var h = H{ .handler = .{ .vtable = &H.vtable } }; - var watcher = try Watcher.init(allocator, &h.handler); + var watcher = try Watcher.init(init.io, init.gpa, &h.handler); defer watcher.deinit(); try watcher.watch("."); diff --git a/examples/simple-variant.zig b/examples/simple-variant.zig index 8c76002..146b410 100644 --- a/examples/simple-variant.zig +++ b/examples/simple-variant.zig @@ -35,11 +35,10 @@ const H = struct { } }; -pub fn main() !void { - const allocator = std.heap.page_allocator; +pub fn main(init: std.process.Init) !void { var h = H{ .handler = .{ .vtable = &H.vtable } }; - var watcher = try Watcher.init(allocator, &h.handler); + var watcher = try Watcher.init(init.io, init.gpa, &h.handler); defer watcher.deinit(); try watcher.watch("."); - std.Thread.sleep(std.time.ns_per_s * 60); + std.Io.sleep(init.io, std.Io.Duration.fromMilliseconds(60_000), .awake) catch {}; }