您可以使用渠道实施超时模式:
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会阻塞,直到
client.Call返回或
timeoutNanoseconds经过。



