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++ {
s <- true
go func(j int) {
resp, err := c.Hello(ctx, &pb.HelloReq{Subject: strings.Join(os.Args[2:], " ")}) resp, err := c.Hello(ctx, &pb.HelloReq{Subject: strings.Join(os.Args[2:], " ")})
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "hello: %#v\n", err) fmt.Fprintf(os.Stderr, "hello: %#v\n", err)
os.Exit(1) os.Exit(1)
} }
fmt.Printf("0x%08x: %#v\n", i, resp) fmt.Printf("0x%08x: %#v\n", j, resp)
<-s
}(i)
} }
} }