build(zig-0.16): update example code in README and examples/ for zig-0.16

This commit is contained in:
CJ van den Berg 2026-04-13 12:13:51 +02:00
parent 82b095bdb8
commit 815146c375
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
4 changed files with 16 additions and 17 deletions

View file

@ -81,7 +81,7 @@ The Watch is written in **Zig** and built using the Zig build system.
## Requirements ## 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 ## Build CLI
@ -145,11 +145,13 @@ const H = struct {
} }
}; };
var h = H{ .handler = .{ .vtable = &H.vtable } }; pub fn main(init: std.process.Init) !void {
var watcher = try nightwatch.Default.init(allocator, &h.handler); var h = H{ .handler = .{ .vtable = &H.vtable } };
defer watcher.deinit(); var watcher = try nightwatch.Default.init(init.io, init.gpa, &h.handler);
try watcher.watch("/path/to/dir"); defer watcher.deinit();
// watcher delivers events on a background thread until 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. See the [`examples/`](examples/) directory for complete, buildable programs.

View file

@ -23,11 +23,10 @@ const H = struct {
} }
}; };
pub fn main() !void { pub fn main(init: std.process.Init) !void {
const allocator = std.heap.page_allocator;
var h = H{ .handler = .{ .vtable = &H.vtable } }; 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(); defer watcher.deinit();
try watcher.watch("."); 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 {};
} }

View file

@ -38,10 +38,9 @@ const H = struct {
} }
}; };
pub fn main() !void { pub fn main(init: std.process.Init) !void {
const allocator = std.heap.page_allocator;
var h = H{ .handler = .{ .vtable = &H.vtable } }; 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(); defer watcher.deinit();
try watcher.watch("."); try watcher.watch(".");

View file

@ -35,11 +35,10 @@ const H = struct {
} }
}; };
pub fn main() !void { pub fn main(init: std.process.Init) !void {
const allocator = std.heap.page_allocator;
var h = H{ .handler = .{ .vtable = &H.vtable } }; 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(); defer watcher.deinit();
try watcher.watch("."); 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 {};
} }