Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/subscription.zig
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,17 @@ pub const Subscription = struct {

/// Unsubscribe from the server and release the user reference.
/// After calling this, the subscription should not be used.
///
/// Do not call from the subscription's own message handler: this joins
/// that handler's task, and a task cannot wait for itself.
pub fn deinit(self: *Subscription) void {
// Join the handler while the caller's reference still keeps the
// subscription alive: a handler that reaches its autounsubscribe
// limit drops the connection's reference itself, and must never be
// the one dropping the last reference, since destroy() joins it.
self.messages.close();
self.handler_group.cancel(self.nc.io);

self.nc.unsubscribe(self);
self.release(); // Release user reference
}
Expand Down
Loading