nsqio / go-nsq

The official Go package for NSQ
MIT License
2.59k stars 444 forks source link

why "connectedFlag" not set zero when Stop() called #291

Closed TT6033 closed 3 years ago

TT6033 commented 4 years ago

connectedFlag =1 when ConnectToNSQLookupd called why "connectedFlag" not set zero when Stop() called?

ploxiln commented 4 years ago

... just because it wasn't needed. It is only used in one place, to ensure that handlers are not added after starting connections:

func (r *Consumer) AddConcurrentHandlers(handler Handler, concurrency int) {
    if atomic.LoadInt32(&r.connectedFlag) == 1 {
        panic("already connected")
    }

It is assumed that after Stop() the process will exit, or will create a new Consumer when needed again.

TT6033 commented 4 years ago

It is only used twice....because some Strange reason. I think it should be reset when stop the connection