Self-explanatory :-) Actually cause I feel lazy today.
1 2 3 4 5 6 7 8 9 10 11
type ReplicatedClient interface { // Init initializes the client to use the given servers. // To make a particular request later, // the client can use callOne(srv, args), where srv // is one of the servers from the list Init(servers []string, callOne(string, Args) Reply) // Call makes a request to an available server. // Multiple gouroutines may call Call concurrently. Call(args Args) Reply }
var r result for off := 0; off < len(c.servers); off++ { id := (prefer + off) % len(c.servers) gofunc() { done <- result{id, c.callOne(c.servers[id], args)} }() select { case r = <-done: goro Done case <-t.C: t.Reset(timeout) } }