RPC是否有超时机制? [英] Does RPC have a timeout mechanism?
本文介绍了RPC是否有超时机制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果RPC没有超时机制,如果它试图调用关闭的服务器的RPC方法,我该如何杀死RPC调用?
If RPC does not have a timeout mechanism, how do I "kill" an RPC call if it is trying to call an RPC method of a server that is closed?
推荐答案
您可以使用渠道实施超时模式:
You can use channels to implement a timeout pattern:
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
}
选择会阻塞,直到 client.Call
返回或 timeoutNanoseconds
已过。
The select
will block until either client.Call
returns or timeoutNanoseconds
elapsed.
这篇关于RPC是否有超时机制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文