Skip to content

Commit

Permalink
consumer: only let exit() run once
Browse files Browse the repository at this point in the history
  • Loading branch information
mreiferson committed Jan 6, 2015
1 parent a661be2 commit 71d3b1d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ type Consumer struct {
stopFlag int32
connectedFlag int32
stopHandler sync.Once
exitHandler sync.Once

// read from this channel to block until consumer is cleanly stopped
StopChan chan int
Expand Down Expand Up @@ -1079,9 +1080,11 @@ func (r *Consumer) shouldFailMessage(message *Message, handler interface{}) bool
}

func (r *Consumer) exit() {
close(r.exitChan)
r.wg.Wait()
close(r.StopChan)
r.exitHandler.Do(func() {
close(r.exitChan)
r.wg.Wait()
close(r.StopChan)
})
}

func (r *Consumer) log(lvl LogLevel, line string, args ...interface{}) {
Expand Down

0 comments on commit 71d3b1d

Please sign in to comment.