Skip to content

Commit 7305875

Browse files
authored
Merge pull request #250 from Boris-Plato/example_fix
Example fix
2 parents e61228a + 7ba88cc commit 7305875

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

_examples/pubsub/pubsub.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,12 @@ func publish(sessions chan chan session, messages <-chan message) {
9191
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
9292
defer cancel()
9393

94+
pending := make(chan message, 1)
95+
9496
for session := range sessions {
9597
var (
9698
running bool
9799
reading = messages
98-
pending = make(chan message, 1)
99100
confirm = make(chan amqp.Confirmation, 1)
100101
)
101102

@@ -117,6 +118,7 @@ func publish(sessions chan chan session, messages <-chan message) {
117118
select {
118119
case confirmed, ok := <-confirm:
119120
if !ok {
121+
pub.Close()
120122
break Publish
121123
}
122124
if !confirmed.Ack {
@@ -190,6 +192,7 @@ func subscribe(sessions chan chan session, messages chan<- message) {
190192
messages <- msg.Body
191193
sub.Ack(msg.DeliveryTag, false)
192194
}
195+
sub.Close()
193196
}
194197
}
195198

0 commit comments

Comments
 (0)