public final class FutureObserver<T>
extends java.lang.Object
implements io.grpc.stub.StreamObserver<T>
CompletableFuture
view on the stream.
This implementation works only with the unary gRPC calls, i.e. FutureObserver.onNext(Object)
cannot
be called more then once.
Modifier and Type | Method and Description |
---|---|
static <T> FutureObserver<T> |
create()
Creates a new instance of
FutureObserver . |
void |
onCompleted() |
void |
onError(java.lang.Throwable t) |
void |
onNext(T value) |
java.util.concurrent.CompletableFuture<T> |
toFuture()
Retrieves the future view on this observer result.
|
static <T> FutureObserver<T> |
withDefault(T defaultValue)
Creates a new instance of
FutureObserver with the given defaultValue . |
public static <T> FutureObserver<T> withDefault(T defaultValue)
FutureObserver
with the given defaultValue
.
The default value is used only if the FutureObserver.onNext(Object)
method is never invoked and
the stream is completed. In such case, the future view is
completed with the given value.
T
- the type of the observed streamdefaultValue
- the default value to complete the future withFutureObserver
public static <T> FutureObserver<T> create()
FutureObserver
.
In case if the stream is completed with no value, the future
view completed with null
.
T
- the type of the observed streamFutureObserver
FutureObserver.withDefault(Object)
public void onError(java.lang.Throwable t)
onError
in interface io.grpc.stub.StreamObserver<T>
public void onCompleted()
onCompleted
in interface io.grpc.stub.StreamObserver<T>
public java.util.concurrent.CompletableFuture<T> toFuture()
The future is completed when:
FutureObserver.onNext(Object)
;