reply and returns the first one that comes back. Is this a bad idea? Is
it possible that the reply will get corrupted since there will be multiple
calls to client.codec.ReadResponseBody(call.Reply)?
Here is the function:
func FirstTimeout(hosts []string, method string, args interface{}, reply
interface{}, timeout time.Duration) error {
ch := make(chan *rpc.Call, len(hosts))
numCalls := 0
var oerr error
for _, host := range hosts {
c, err := clientcache.Client(host)
if err != nil {
oerr = err
continue
}
c.Go(method, args, reply, ch)
numCalls++
}
if numCalls == 0 {
return oerr
}
select {
case r := <-ch:
reply = r.Reply
return r.Error
case <-time.After(timeout):
return fmt.Errorf("timeout calling %s on %v (%s)", method, hosts, timeout)
}
panic("never reached")
}
Thanks!
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.