net/rpc .Call 和 .Go 有什么区别?

What is the difference between net/rpc .Call vs .Go?

我刚刚开始使用 Golang 和 net/rpc 包。我试图了解您何时可以使用异步 client.Go() 调用大多数在线示例使用的 client.Call() 方法。会通过类似

的方式异步调用 client.Call
go client.Call(...)

本质上与使用 client.Go 调用相同?我也在网上看到过这个例子(例如同时调用多个 RPC)。

documented:

Go invokes the function asynchronously. It returns the Call structure representing the invocation. The done channel will signal when the call is complete by returning the same Call object. If done is nil, Go will allocate a new channel. If non-nil, done must be buffered or Go will deliberately crash.

这意味着它发出命令,但不等待它完成

来自 contrast:

Call invokes the named function, waits for it to complete, and returns its error status.

这两个方法都没有直接在 goroutine 中执行*——这留给调用者作为练习(因此可能有人认为 Go 是用词不当)。

如果你看一下source to Call,也许就更清楚了:

func (client *Client) Call(serviceMethod string, args interface{}, reply 
interface{}) error {
    call := <-client.Go(serviceMethod, args, reply, make(chan *Call, 1)).Done
    return call.Error
}

所以实际上,CallGo 的包装器,它等待操作完成,而 Go 是底层函数,等待调用者.

*很明显,在后台某处涉及一个goroutine,因为这是一个非阻塞操作。