Skip to content

Commit

Permalink
Topic.Start() try 2 style 2
Browse files Browse the repository at this point in the history
  • Loading branch information
ploxiln committed Jul 9, 2018
1 parent 8af7608 commit 4db8a66
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions nsqd/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,28 +236,27 @@ func (t *Topic) messagePump() {
var memoryMsgChan chan *Message
var backendChan chan []byte

// before Start()
gotChannels := false
started := false
for !started {
// before Start(), avoid blocking Pause() or GetChannel()
for {
select {
case <-t.channelUpdateChan:
gotChannels = true
continue
case <-t.pauseChan:
// no effect before channels added
continue
case <-t.exitChan:
goto exit
case <-t.startChan:
started = true
}
break;
}
if gotChannels {
go func() {
select {
case t.channelUpdateChan <- 1:
case <-t.exitChan:
}
}()
t.RLock()
for _, c := range t.channelMap {
chans = append(chans, c)
}
t.RUnlock()
if len(chans) > 0 && !t.IsPaused() {
memoryMsgChan = t.memoryMsgChan
backendChan = t.backend.ReadChan()
}

// main loop
Expand Down

0 comments on commit 4db8a66

Please sign in to comment.