Open verihelp-vaibhav opened 5 years ago
In your snippet above, you can call status.cancel()
.
Okay, I found the way to cancel the previous stream. But still not sure how to disconnect my client completely. For anyone wondering how to cancel the previous stream, here's a sample -
var stream;
function getStream(request) {
if (stream) {
stream.cannel();
}
stream = SomeServiceClient.getMyStream(request, {});
}
function myFuncThatUsesStream(parameters) {
getStream();
// do something with stream now
stream.on('data', ....
}
In your snippet above, you can call
status.cancel()
.
Thanks @stanley-cheung, I knew about the cancel but didn't have the object from previous call to cancel. I figured it out and pasted my code above.
Do you have any idea about completely disconnecting the client?
How do you cancel a request when using the promise client? as the client.request only returns a promise?
+1
Need to know how to cancel using the promise client. Please provide some docs
+1
I'd like to know how to cancel a promise client, too.
Hi! Thank for asking!
This feature was requested in https://github.com/grpc/grpc-web/pull/1240 and i'm planning on adding a new option for this. Will update the PR when it's done.
Thanks!
Re-opening this issue for the Promise client use case.
Hi, I can't find any method to disconnect the client as per my command. Using an example snippet here -
The problem I'm encountering is - user clicks a button, I make a request to the gRPC server and start receiving data in a stream. If the user clicks again, I start receiving data again in another stream. I want to disconnect any previous streams/connections so that I can receive only one stream at a time. Any help/suggestions would be greatly appreciated! (I know I could disable the click till the stream is finished, but that's not what I'm looking for.)