< pre>import “time”
c := make(chan error, 1)
go func() {c <- client.Call("Service", args, &result)} ( )
select {
case err := <-c:
// use err and result
case <-time.After(timeoutNanoseconds):
// call timed out
)
Select will block until client.Call returns or timeoutNanoseconds passes.
If RPC does not have a timeout mechanism, if it does Trying to call the RPC method of a closed server, how to “terminate” the RPC call?
You can use channels to implement timeout mode:
import "time"
c := make(chan error, 1)
go func() {c <- client.Call("Service", args, &result)} ()
select {
case err := <-c:
// use err and result
case <-time.After(timeoutNanoseconds):
// call timed out
}
< p>Select will block until client.Call returns or timeoutNanoseconds passes.