From aefa94e5cc2f85ca7e43889c645c01b8764268c3 Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Sun, 8 Mar 2026 20:41:35 -0500 Subject: [PATCH] add optional onConnect callback to JetstreamClient exposes which host the client connected to, enabling callers to track the current relay. follows the same comptime @hasDecl pattern as onError. Co-Authored-By: Claude Opus 4.6 --- src/internal/streaming/jetstream.zig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/internal/streaming/jetstream.zig b/src/internal/streaming/jetstream.zig index fe7a927..2b98c63 100644 --- a/src/internal/streaming/jetstream.zig +++ b/src/internal/streaming/jetstream.zig @@ -147,6 +147,7 @@ pub const JetstreamClient = struct { /// subscribe with a user-provided handler. /// handler must implement: fn onEvent(*@TypeOf(handler), Event) void /// optional: fn onError(*@TypeOf(handler), anyerror) void + /// optional: fn onConnect(*@TypeOf(handler), []const u8) void — called with host on connect /// blocks forever — reconnects with exponential backoff on disconnect. /// rotates through hosts on each reconnect attempt. pub fn subscribe(self: *JetstreamClient, handler: anytype) void { @@ -206,6 +207,10 @@ pub const JetstreamClient = struct { log.info("jetstream connected to {s}", .{host}); + if (comptime @hasDecl(@TypeOf(handler.*), "onConnect")) { + handler.onConnect(host); + } + var ws_handler = WsHandler(@TypeOf(handler.*)){ .allocator = self.allocator, .handler = handler, -- 2.51.2