Skip to content

Commit 9870db1

Browse files
committed
stub: Document that noop onCancelHandler is useful
setOnCancelHandler tells gRPC that the application is handling cancellation. But it's fine to have noop behavior within the handler itself if the application doesn't need it. It is just a way to opt-in to the more recent no-exception-from-onNext behavior. Let's mention this use-case in the docs to make it more obvious it is a possibility. Came up as part of grpc#8409.
1 parent 2260381 commit 9870db1

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

stub/src/main/java/io/grpc/stub/ServerCallStreamObserver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ public abstract class ServerCallStreamObserver<V> extends CallStreamObserver<V>
5454
* service returns its {@code StreamObserver}.
5555
*
5656
* <p>Setting the onCancelHandler will suppress the on-cancel exception thrown by
57-
* {@link #onNext}.
57+
* {@link #onNext}. If the caller is already handling cancellation via polling or cannot
58+
* substantially benefit from observing cancellation, using a no-op {@code onCancelHandler} is
59+
* useful just to suppress the {@code onNext()} exception.
5860
*
5961
* @param onCancelHandler to call when client has cancelled the call.
6062
*/

0 commit comments

Comments
 (0)