From d812dba34788ec7e750b3ddc1e1f81a8d239fcbf Mon Sep 17 00:00:00 2001 From: flowerinthenight Date: Mon, 23 Sep 2024 13:23:04 +0900 Subject: [PATCH] core: update get members api --- README.md | 2 +- src/main.zig | 16 ++++++++-------- src/zgroup.zig | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8d7621c..fb2c575 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ $ ./zig-out/bin/zgroup group1 0.0.0.0:8083 To get the current members of the group, you can try something like: ```zig -const members = try fleet.memberNames(gpa.allocator()); +const members = try fleet.getMembers(gpa.allocator()); defer members.deinit(); for (members.items, 0..) |v, i| { diff --git a/src/main.zig b/src/main.zig index 9eaa8c8..a29dcb4 100644 --- a/src/main.zig +++ b/src/main.zig @@ -196,14 +196,14 @@ pub fn main() !void { // log.info("--- leader={s}", .{ldr}); // } - // if (i > 0 and @mod(i, 10) == 0) { - // const members = try fleet.memberNames(gpa.allocator()); - // defer members.deinit(); - // for (members.items, 0..) |v, j| { - // defer gpa.allocator().free(v); - // log.info("(from main) member[{d}]: {s}", .{ j, v }); - // } - // } + if (i > 0 and @mod(i, 10) == 0) { + const members = try fleet.getMembers(gpa.allocator()); + defer members.deinit(); + for (members.items, 0..) |v, j| { + defer gpa.allocator().free(v); + log.info("(from main) member[{d}]: {s}", .{ j, v }); + } + } } } diff --git a/src/zgroup.zig b/src/zgroup.zig index 70ee086..8650438 100644 --- a/src/zgroup.zig +++ b/src/zgroup.zig @@ -266,7 +266,7 @@ pub fn Fleet(UserData: type) type { /// Returns a list of active members from the group/cluster. Caller owns the returning /// list, as well as each items in the array, which are duplicated from the internal /// list to prevent crashes during access due to potential changes in the main list. - pub fn memberNames(self: *Self, allocator: std.mem.Allocator) !std.ArrayList([]const u8) { + pub fn getMembers(self: *Self, allocator: std.mem.Allocator) !std.ArrayList([]const u8) { var tmp = std.ArrayList([]const u8).init(allocator); defer tmp.deinit();