示例#1
0
// SendAsync sends `req` to the other end and calls callback on the response.
func (cnv *Conversation) SendAsync(req *wire.Request, callback transfer.AsyncFunc) error {
	cnv.Lock()
	defer cnv.Unlock()

	// Add a nonce so that the same message is guaranteed to result
	// in a different ciphertext:
	req.Nonce = rand.Int63()

	// Broadcast messages usually do not register a callback.
	// (it wouldn't have been called anyways)
	if callback != nil {
		cnv.notifees[req.ID] = callback
	}

	return cnv.proto.Send(req)
}