mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 17:20:24 +08:00
update rpc example
This commit is contained in:
parent
0f8140031a
commit
974c19d6d3
@ -5,6 +5,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
|
||||
"github.com/tal-tech/go-zero/core/discov"
|
||||
"github.com/tal-tech/go-zero/example/rpc/remote/stream"
|
||||
@ -33,22 +34,21 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
done := make(chan struct{})
|
||||
var wg sync.WaitGroup
|
||||
go func() {
|
||||
defer func() {
|
||||
done <- struct{}{}
|
||||
}()
|
||||
for i := 0; i < 3; i++ {
|
||||
for {
|
||||
resp, err := stm.Recv()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println("=>", resp.Greet)
|
||||
wg.Done()
|
||||
}
|
||||
}()
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
wg.Add(1)
|
||||
fmt.Println("<=", name)
|
||||
if err = stm.Send(&stream.StreamReq{
|
||||
Name: name,
|
||||
@ -57,5 +57,5 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
<-done
|
||||
wg.Wait()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user