wenfengwang commented on a change in pull request #97: fix remote timeout unit 
and add shutdown method
URL: https://github.com/apache/rocketmq-client-go/pull/97#discussion_r300972943
 
 

 ##########
 File path: internal/kernel/client.go
 ##########
 @@ -124,45 +127,70 @@ func (c *RMQClient) Start() {
                go func() {
                        // delay
                        time.Sleep(50 * time.Millisecond)
+                       c.UpdateTopicRouteInfo()
                        for {
-                               c.UpdateTopicRouteInfo()
-                               time.Sleep(_PullNameServerInterval)
+                               select {
+                               case <-ctx.Done():
+                                       return
+                               case <-time.Tick(_PullNameServerInterval):
+                                       c.UpdateTopicRouteInfo()
+                               }
                        }
                }()
 
                // TODO cleanOfflineBroker & sendHeartbeatToAllBrokerWithLock
                go func() {
+                       cleanOfflineBroker()
+                       c.SendHeartbeatToAllBrokerWithLock()
                        for {
-                               cleanOfflineBroker()
-                               c.SendHeartbeatToAllBrokerWithLock()
-                               time.Sleep(_HeartbeatBrokerInterval)
+                               select {
+                               case <-ctx.Done():
+                                       return
+                               case <-time.Tick(_HeartbeatBrokerInterval):
+                                       cleanOfflineBroker()
+                                       c.SendHeartbeatToAllBrokerWithLock()
+                               }
                        }
                }()
 
                // schedule persist offset
                go func() {
-                       //time.Sleep(10 * time.Second)
+                       c.consumerMap.Range(func(key, value interface{}) bool {
+                               consumer := value.(InnerConsumer)
+                               consumer.PersistConsumerOffset()
+                               return true
+                       })
                        for {
-                               c.consumerMap.Range(func(key, value 
interface{}) bool {
-                                       consumer := value.(InnerConsumer)
-                                       consumer.PersistConsumerOffset()
-                                       return true
-                               })
-                               time.Sleep(_PersistOffset)
+                               select {
+                               case <-ctx.Done():
+                                       return
+                               case <-time.Tick(_PersistOffset):
+                                       c.consumerMap.Range(func(key, value 
interface{}) bool {
+                                               consumer := 
value.(InnerConsumer)
+                                               consumer.PersistConsumerOffset()
+                                               return true
+                                       })
+                               }
                        }
                }()
 
                go func() {
+                       c.RebalanceImmediately()
                        for {
-                               c.RebalanceImmediately()
-                               time.Sleep(_RebalanceInterval)
+                               select {
+                               case <-ctx.Done():
+                                       return
+                               case <-time.Tick(_RebalanceInterval):
+                                       c.RebalanceImmediately()
+                               }
                        }
                }()
        })
 }
 
 func (c *RMQClient) Shutdown() {
-       // TODO
 
 Review comment:
   > IMO, could we add a field like `state` instead of `cancel`, which is 
updated to `shutdown` when `Shutdown()` called, and return a error like 
`errors.New("client closed")` when `Send*()` called
   
   What's about this?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to