Skip to content

Commit 026002a

Browse files
committed
static method nextAndComplete()
1 parent ebe2b48 commit 026002a

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@
2323
/**
2424
* Utility functions for working with {@link StreamObserver} and it's common subclasses like
2525
* {@link CallStreamObserver}.
26-
*
27-
* @deprecated Of questionable utility and generally not used.
2826
*/
29-
@Deprecated
30-
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/4694")
3127
public final class StreamObservers {
28+
/**
29+
* Utility method to call {@link StreamObserver#onNext(Object)} and
30+
* {@link StreamObserver#onCompleted()} on the specified responseObserver.
31+
*/
32+
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/10957")
33+
public static <T> void nextAndComplete(StreamObserver<T> responseObserver, T response) {
34+
Preconditions.checkNotNull(response, "response");
35+
36+
responseObserver.onNext(response);
37+
responseObserver.onCompleted();
38+
}
39+
3240
/**
3341
* Copy the values of an {@link Iterator} to the target {@link CallStreamObserver} while properly
3442
* accounting for outbound flow-control. After calling this method, {@code target} should no
@@ -40,7 +48,10 @@ public final class StreamObservers {
4048
*
4149
* @param source of values expressed as an {@link Iterator}.
4250
* @param target {@link CallStreamObserver} which accepts values from the source.
51+
* @deprecated Of questionable utility and generally not used.
4352
*/
53+
@Deprecated
54+
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/4694")
4455
public static <V> void copyWithFlowControl(final Iterator<V> source,
4556
final CallStreamObserver<V> target) {
4657
Preconditions.checkNotNull(source, "source");
@@ -80,7 +91,10 @@ public void run() {
8091
*
8192
* @param source of values expressed as an {@link Iterable}.
8293
* @param target {@link CallStreamObserver} which accepts values from the source.
94+
* @deprecated Of questionable utility and generally not used.
8395
*/
96+
@Deprecated
97+
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/4694")
8498
public static <V> void copyWithFlowControl(final Iterable<V> source,
8599
CallStreamObserver<V> target) {
86100
Preconditions.checkNotNull(source, "source");

0 commit comments

Comments
 (0)