make client concurrent

This commit is contained in:
Stephen McQuay 2018-01-26 17:15:13 -08:00
parent 6000071bb6
commit c0406348f6
Signed by: sm
GPG Key ID: 4E4B72F479BA3CE5

View File

@ -32,12 +32,17 @@ func main() {
os.Exit(1) os.Exit(1)
} }
s := make(chan bool, 10)
for i := 0; ; i++ { for i := 0; ; i++ {
resp, err := c.Hello(ctx, &pb.HelloReq{Subject: strings.Join(os.Args[2:], " ")}) s <- true
if err != nil { go func(j int) {
fmt.Fprintf(os.Stderr, "hello: %#v\n", err) resp, err := c.Hello(ctx, &pb.HelloReq{Subject: strings.Join(os.Args[2:], " ")})
os.Exit(1) if err != nil {
} fmt.Fprintf(os.Stderr, "hello: %#v\n", err)
fmt.Printf("0x%08x: %#v\n", i, resp) os.Exit(1)
}
fmt.Printf("0x%08x: %#v\n", j, resp)
<-s
}(i)
} }
} }