Skip to content

Commit

Permalink
Close pubsub topic when broadcaster closes
Browse files Browse the repository at this point in the history
Closes #227
  • Loading branch information
gammazero committed Nov 20, 2024
1 parent c705d01 commit 4bb6115
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pubsub_broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ func NewPubSubBroadcaster(ctx context.Context, psub *pubsub.PubSub, topic string
go func(ctx context.Context, subs *pubsub.Subscription) {
<-ctx.Done()
subs.Cancel()
// subs.Next returns error when subscription closed. Subscription must
// be closed before psubTopic can be closed.
var err error
for err == nil {
_, err = subs.Next(ctx)
}
psubTopic.Close()
}(ctx, subs)

return &PubSubBroadcaster{
Expand Down

0 comments on commit 4bb6115

Please sign in to comment.