Skip to content

Commit

Permalink
core: update get members api
Browse files Browse the repository at this point in the history
  • Loading branch information
flowerinthenight committed Sep 23, 2024
1 parent 5dd8f57 commit d812dba
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
16 changes: 8 additions & 8 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/zgroup.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit d812dba

Please sign in to comment.