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
1 changed files with 11 additions and 6 deletions

View File

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