Skip to content

Commit 5cc94a5

Browse files
authored
stub: Document StreamObserver is an async API
Missing docs were brought up in grpc#8423
1 parent b3ef588 commit 5cc94a5

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
/**
2222
* A refinement of {@link CallStreamObserver} that allows for lower-level interaction with
23-
* client calls.
23+
* client calls. An instance of this class is obtained via {@link ClientResponseObserver}, or by
24+
* manually casting the {@code StreamObserver} returned by a stub.
2425
*
2526
* <p>Like {@code StreamObserver}, implementations are not required to be thread-safe; if multiple
2627
* threads will be writing to an instance concurrently, the application must synchronize its calls.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
/**
2020
* A refinement of {@link CallStreamObserver} to allows for interaction with call
21-
* cancellation events on the server side.
21+
* cancellation events on the server side. An instance of this class is obtained by casting the
22+
* {@code StreamObserver} passed as an argument to service implementations.
2223
*
2324
* <p>Like {@code StreamObserver}, implementations are not required to be thread-safe; if multiple
2425
* threads will be writing to an instance concurrently, the application must synchronize its calls.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@
3131
* not need to be synchronized together; incoming and outgoing directions are independent.
3232
* Since individual {@code StreamObserver}s are not thread-safe, if multiple threads will be
3333
* writing to a {@code StreamObserver} concurrently, the application must synchronize calls.
34+
*
35+
* <p>This API is asynchronous, so methods may return before the operation completes. The API
36+
* provides no guarantees for how quickly an operation will complete, so utilizing flow control via
37+
* {@link ClientCallStreamObserver} and {@link ServerCallStreamObserver} to avoid excessive
38+
* buffering is recommended for streaming RPCs. gRPC's implementation of {@code onError()} on
39+
* client-side causes the RPC to be cancelled and discards all messages, so completes quickly.
40+
*
41+
* <p>gRPC guarantees it does not block on I/O in its implementation, but applications are allowed
42+
* to perform blocking operations in their implementations. However, doing so will delay other
43+
* callbacks because the methods cannot be called concurrently.
3444
*/
3545
public interface StreamObserver<V> {
3646
/**

0 commit comments

Comments
 (0)