mirror of
https://github.com/duanhf2012/origin.git
synced 2026-05-18 06:57:29 +08:00
rpc调用加入超时时间
This commit is contained in:
@@ -8,11 +8,13 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServerError represents an error that has been returned from
|
// 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.
|
// 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 {
|
func (client *Client) Call(serviceMethod string, args interface{}, reply interface{}) error {
|
||||||
call := <-client.Go(serviceMethod, args, reply, make(chan *Call, 1)).Done
|
select {
|
||||||
return call.Error
|
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))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user