Closed kienvtqhi closed 1 year ago
I would expect that the stream is closed on the client side when server side closes the stream. Have you tried adding on onDone
callback when listening for events from the stream?
@mraleph Thanks for your answer and sorry for the late response
Stream<Match> registerListenerForNewMatch(String userId) async* {
try {
await unregisterListenerMatchStream();
CreateMatchStreamRequest channel = CreateMatchStreamRequest()..userId = userId;
_chatMatchStream = grpcServiceClient!.createMatchStream(channel);
if (_chatMatchStream != null) {
logger.e(
"gRPC match streaming...: ${DateTime.now().millisecondsSinceEpoch} -> $_chatMatchStream");
}
await for (var msg in _chatMatchStream!) {
logger.e("gRPC match stream message received: $msg");
yield msg;
}
} catch (e) {
logger.e(
"gRPC match subscripe error: ${DateTime.now().millisecondsSinceEpoch} -> $e");
await unregisterListenerMatchStream();
}
}
Have you tried adding on onDone callback when listening for events from the stream?
I attached the code I am using to listen the event from the stream from gRPC server. How can I add onDone
callback?
In this case you don't need onDone
. await for
should terminate when the server stops sending data and closes the stream. Does not it not terminate for you?
grpc-dart: 3.1.0
Hello,I am using grpc server stream in my Flutter app to receive data from server side. How can the client side (Flutter app) know that when the server completed sending data to the stream? I used postman to test the server stream grpc function and it know it.
Thank you so much