From 4445b377f83233a0c48b3f2696f6f50d5af8776e Mon Sep 17 00:00:00 2001 From: boyce Date: Thu, 28 Feb 2019 14:08:07 +0800 Subject: [PATCH] =?UTF-8?q?rpc=E8=B0=83=E7=94=A8=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rpc/client.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rpc/client.go b/rpc/client.go index 784c8a6..b938502 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -8,11 +8,13 @@ import ( "bufio" "encoding/gob" "errors" + "fmt" "io" "log" "net" "net/http" "sync" + "time" ) // ServerError represents an error that has been returned from @@ -326,6 +328,12 @@ func (client *Client) Go(serviceMethod string, args interface{}, reply interface // Call invokes the named function, waits for it to complete, and returns its error status. func (client *Client) Call(serviceMethod string, args interface{}, reply interface{}) error { - call := <-client.Go(serviceMethod, args, reply, make(chan *Call, 1)).Done - return call.Error + select { + case call := <-client.Go(serviceMethod, args, reply, make(chan *Call, 1)).Done: + return call.Error + case <-time.After(10 * time.Second): + } + + //call := <-client.Go(serviceMethod, args, reply, make(chan *Call, 1)).Done + return errors.New(fmt.Sprintf("Call RPC %s is time out 10s", serviceMethod)) }