Getting started
Add the dependency
Section titled “Add the dependency”In a new project, run:
mkdir zigrupt-democd zigrupt-demozig initzig fetch --save=zigrupt git+https://github.com/sarthakvk/zigrupt.gitIn build.zig, add these lines after the exe declaration so main.zig can
import zigrupt:
const zigrupt = b.dependency("zigrupt", .{ .target = target, .optimize = optimize });exe.root_module.addImport("zigrupt", zigrupt.module("zigrupt"));Try it
Section titled “Try it”Replace src/main.zig with:
const std = @import("std");const zigrupt = @import("zigrupt");
const Event = struct { value: usize };
fn handle(events: []const Event) usize { for (events) |event| std.debug.print("{d}\n", .{event.value}); return events.len;}
const BusySpin = zigrupt.waiting_strategy.BusySpin;const Bus = zigrupt.EventBus(Event, false, &.{handle}, BusySpin, BusySpin);
pub fn main() !void { var bus = try Bus.init(std.heap.page_allocator, 64, 8); defer bus.deinit(); try bus.start(); errdefer bus.stop() catch {};
try bus.produce(.{ .value = 42 }); try bus.stop();}zig build runThis prints 42.
Continue with concepts and event ownership before passing pointers or slices.
