How to stop client streams correctly?

40 views
Skip to first unread message

afshi...@gmail.com

unread,
Jul 13, 2020, 2:19:16 AM7/13/20
to grpc.io

Hi.

Let's assume that I can written an asynchronous grpc client that send a stream and gets a response. This situation uses `ClientAsyncWriter` class. How we can stop sending message in middle of stream? For example, we detect a problem with our stream of messages after sending few messages and need to stop sending messages. What we can do? because there is no method to stop sending data with error. The only way that came to my mind was to cancel rpc connection by using `TryCancel` on the context. Is this a correct way to handle this situation? or should I use another method?

Best Regards

Yang Gao

unread,
Jul 20, 2020, 2:21:25 PM7/20/20
to grpc.io
Yes. If you want to abort the stream, just cancel it with TryCancel.
Reply all
Reply to author
Forward
0 new messages