Skip to content

Commit

Permalink
Fixed disconnect before unsubscribe condition
Browse files Browse the repository at this point in the history
  • Loading branch information
levb committed Feb 27, 2024
1 parent 9643d51 commit f7729ad
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (r *receiver) receive(readyCh chan struct{}, doneCh chan struct{}) {
r.durPublished = new(atomic.Int64)
r.bc = new(atomic.Int64)
r.start = time.Now()
r.allReceivedCh = make(chan struct{})
r.allReceivedCh = make(chan struct{}, 1)

token := cl.Subscribe(r.topic, byte(r.qos), r.msgHandler)
if token.Wait() && token.Error() != nil {
Expand All @@ -82,13 +82,13 @@ func (r *receiver) receive(readyCh chan struct{}, doneCh chan struct{}) {
readyCh <- struct{}{}
}

// wait for all messages to be received, then clean up and signal to the caller.
<-r.allReceivedCh

token = cl.Unsubscribe(r.topic)
if token.Wait() && token.Error() != nil {
log.Fatal(token.Error())
}

// wait for all messages to be received, then clean up and signal to the caller.
<-r.allReceivedCh
}
}

Expand Down

0 comments on commit f7729ad

Please sign in to comment.