This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch 1.5
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/1.5 by this push:
     new 5520fa1  performance optimization: change time.After => time.NewTimer 
(#1293)
5520fa1 is described below

commit 5520fa1783c9e3d73b45be74ec5810442da848d9
Author: Mark4z <[email protected]>
AuthorDate: Mon Jul 5 10:27:41 2021 +0800

    performance optimization: change time.After => time.NewTimer (#1293)
---
 protocol/grpc/server.go    | 5 +++--
 tools/cli/client/client.go | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/protocol/grpc/server.go b/protocol/grpc/server.go
index 23460a0..ab8267a 100644
--- a/protocol/grpc/server.go
+++ b/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()
 
        for {
                select {
@@ -124,7 +125,7 @@ func waitGrpcExporter(providerServices 
map[string]*config.ServiceConfig) {
                        if pLen == mLen {
                                return
                        }
-               case <-ta:
+               case <-ta.C:
                        panic("wait grpc exporter timeout when start grpc 
server")
                }
        }
diff --git a/tools/cli/client/client.go b/tools/cli/client/client.go
index fd15939..70b6c96 100644
--- a/tools/cli/client/client.go
+++ b/tools/cli/client/client.go
@@ -143,11 +143,12 @@ func (t *TelnetClient) processSingleRequest(req 
*protocol.Request, userPkg inter
        go t.readInputData(string(inputData), requestDataChannel)
        go t.readServerData(t.conn, responseDataChannel)
 
-       timeAfter := time.After(t.responseTimeout)
+       timeAfter := time.NewTimer(t.responseTimeout)
+       defer timeAfter.Stop()
 
        for {
                select {
-               case <-timeAfter:
+               case <-timeAfter.C:
                        log.Println("request timeout to:", t.tcpAddr)
                        return
                case request := <-requestDataChannel:

Reply via email to