Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stub: Document StreamObserver is an async API #8449

Merged
merged 2 commits into from Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -20,7 +20,8 @@

/**
* A refinement of {@link CallStreamObserver} that allows for lower-level interaction with
* client calls.
* client calls. An instance of this class is obtained via {@link ClientResponseObserver}, or by
dapengzhang0 marked this conversation as resolved.
Show resolved Hide resolved
* manually casting the {@code StreamObserver} returned by a stub.
*
* <p>Like {@code StreamObserver}, implementations are not required to be thread-safe; if multiple
* threads will be writing to an instance concurrently, the application must synchronize its calls.
Expand Down
Expand Up @@ -18,7 +18,8 @@

/**
* A refinement of {@link CallStreamObserver} to allows for interaction with call
* cancellation events on the server side.
* cancellation events on the server side. An instance of this class is obtained by casting the
* {@code StreamObserver} passed as an argument to service implementations.
*
* <p>Like {@code StreamObserver}, implementations are not required to be thread-safe; if multiple
* threads will be writing to an instance concurrently, the application must synchronize its calls.
Expand Down
10 changes: 10 additions & 0 deletions stub/src/main/java/io/grpc/stub/StreamObserver.java
Expand Up @@ -31,6 +31,16 @@
* not need to be synchronized together; incoming and outgoing directions are independent.
* Since individual {@code StreamObserver}s are not thread-safe, if multiple threads will be
* writing to a {@code StreamObserver} concurrently, the application must synchronize calls.
*
* <p>This API is asynchronous, so methods may return before the operation completes. The API
* provides no guarantees for how quickly an operation will complete, so utilizing flow control via
* {@link ClientCallStreamObserver} and {@link ServerCallStreamObserver} to avoid excessive
* buffering is recommended for streaming RPCs. gRPC's implementation of {@code onError()} on
* client-side causes the RPC to be cancelled and discards all messages, so completes quickly.
dapengzhang0 marked this conversation as resolved.
Show resolved Hide resolved
*
* <p>gRPC guarantees it does not block on I/O in its implementation, but applications are allowed
* to perform blocking operations in their implementations. However, doing so will delay other
* callbacks because the methods cannot be called concurrently.
*/
public interface StreamObserver<V> {
/**
Expand Down