Does the GO – RPC have timeout mechanisms?

If RPC does not have a timeout mechanism, if it tries to call the RPC method of a closed server, how to “terminate” the RPC call?
You can use channels to implement timeout mode:

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

Leave a Comment

Your email address will not be published.