ooyeku/vigil
A process supervision and management library for Zig, inspired by Erlang/OTP's supervisor model.
A process supervision and inter-process communication library for Zig, designed for building reliable distributed systems and concurrent applications.
Fetch latest release:
zig fetch --save "git+https://github.com/ooyeku/vigil/#v0.1.1"
Add as a dependency in your build.zig.zon
:
const vigil = b.dependency("vigil", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("vigil", vigil.module("vigil_lib"));
b.installArtifact(exe);
const std = @import("std");
const vigil = @import("vigil");
// Initialize a mailbox
var mailbox = vigil.ProcessMailbox.init(allocator, .{
.capacity = 100,
.max_message_size = 1024 * 1024, // 1MB
.default_ttl_ms = 5000, // 5 seconds
.priority_queues = true,
.enable_deadletter = true,
});
defer mailbox.deinit();
// Send a high-priority message
const msg = try vigil.Message.init(
allocator,
"status_update",
"worker_1",
"CPU usage high",
.cpuWarning,
.high,
5000, // 5 second TTL
);
try mailbox.send(msg);
// Process messages with priority handling
while (mailbox.receive()) |received| {
defer received.deinit();
if (received.signal) |signal| {
switch (signal) {
.cpuWarning => handleCpuWarning(received),
.healthCheck => sendHealthStatus(),
else => handleOtherSignal(received),
}
}
} else |err| switch (err) {
error.EmptyMailbox => break,
else => return err,
}
MIT - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.