You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/07/03 23:48:56 UTC

[GitHub] [dubbo-go] AlexStocks commented on a change in pull request #1293: performance optimization: change time.After => time.NewTimer

AlexStocks commented on a change in pull request #1293:
URL: https://github.com/apache/dubbo-go/pull/1293#discussion_r663422840



##########
File path: protocol/grpc/server.go
##########
@@ -115,7 +115,8 @@ func waitGrpcExporter(providerServices map[string]*config.ServiceConfig) {
 	t := time.NewTicker(50 * time.Millisecond)
 	defer t.Stop()
 	pLen := len(providerServices)
-	ta := time.After(10 * time.Second)
+	ta := time.NewTimer(10 * time.Second)
+	defer ta.Stop()

Review comment:
       hey, guy, this is not a good code example. just stop the timer in no ta.C case branch. Another method is as follows:
   
   ```go
   var flag uberatomic.Bool
   
   defer func() {
       if !flag {
           ta.Stop()
       }
   }
   ...
   
   case time.C:
   
   flag.Set(true)
   
   ```




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org