Strip some code from the client
This commit is contained in:
parent
f6a7ef7bc0
commit
40cd086543
@ -10,7 +10,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/youtube/vitess/go/trace"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -216,38 +215,15 @@ func (client *client) Close() error {
|
|||||||
return client.codec.Close()
|
return client.codec.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go invokes the function asynchronously. It returns the call structure representing
|
// call invokes the named function, waits for it to complete, and returns its error status.
|
||||||
// the invocation. The done channel will signal when the call is complete by returning
|
func (client *client) Call(ctx context.Context, service string, serviceMethod string, args interface{}, reply interface{}) error {
|
||||||
// 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.
|
|
||||||
func (client *client) Go(ctx context.Context, service, serviceMethod string, args interface{}, reply interface{}, done chan *call) *call {
|
|
||||||
span := trace.NewSpanFromContext(ctx)
|
|
||||||
span.StartClient(serviceMethod)
|
|
||||||
defer span.Finish()
|
|
||||||
|
|
||||||
cal := new(call)
|
cal := new(call)
|
||||||
cal.Service = service
|
cal.Service = service
|
||||||
cal.ServiceMethod = serviceMethod
|
cal.ServiceMethod = serviceMethod
|
||||||
cal.Args = args
|
cal.Args = args
|
||||||
cal.Reply = reply
|
cal.Reply = reply
|
||||||
if done == nil {
|
cal.Done = make(chan *call, 1)
|
||||||
done = make(chan *call, 10) // buffered.
|
|
||||||
} else {
|
|
||||||
// If caller passes done != nil, it must arrange that
|
|
||||||
// done has enough buffer for the number of simultaneous
|
|
||||||
// RPCs that will be using that channel. If the channel
|
|
||||||
// is totally unbuffered, it's best not to run at all.
|
|
||||||
if cap(done) == 0 {
|
|
||||||
log.Panic("rpc: done channel is unbuffered")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cal.Done = done
|
|
||||||
client.send(cal)
|
client.send(cal)
|
||||||
return cal
|
call := <-cal.Done
|
||||||
}
|
|
||||||
|
|
||||||
// call invokes the named function, waits for it to complete, and returns its error status.
|
|
||||||
func (client *client) Call(ctx context.Context, service string, serviceMethod string, args interface{}, reply interface{}) error {
|
|
||||||
call := <-client.Go(ctx, service, serviceMethod, args, reply, make(chan *call, 1)).Done
|
|
||||||
return call.Error
|
return call.Error
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user