Reputation: 4364
I am taking a look at the tutorials of grpc https://grpc.io/docs/tutorials/basic/go.html
The grpc unary call looks something like this
conn, err := grpc.Dial(*serverAddr)
if err != nil {
...
}
defer conn.Close()
client := pb.NewRouteGuideClient(conn)
feature, err := client.GetFeature(context.Background(), &pb.Point{409146138, -746188906})
if err != nil {
...
}
I wanted to know if I call
client.GetFeature
from multiple threads, is it thread safe?
Upvotes: 8
Views: 4958
Reputation: 6546
Looking into this issue you can learn that:
@rubenv asks:
Can I use a client from different threads in parallel?
@iamqizhao replies:
On client, if you want to perform multiple rpc in parallel, you should spawn multiple goroutines to do that since the rpc is synchronous/blocking
the answer is yes, however, a stream can't be shared (source).
@trevorgray, these kinds of concurrency topics are apparently still not documented, per #682.
Upvotes: 6