Class BlockingMultiObserver<T>
- java.lang.Object
-
- java.util.concurrent.CountDownLatch
-
- io.reactivex.rxjava3.internal.observers.BlockingMultiObserver<T>
-
- Type Parameters:
T
- the value type
- All Implemented Interfaces:
CompletableObserver
,MaybeObserver<T>
,SingleObserver<T>
public final class BlockingMultiObserver<T> extends java.util.concurrent.CountDownLatch implements SingleObserver<T>, CompletableObserver, MaybeObserver<T>
A combined Observer that awaits the success or error signal via a CountDownLatch.
-
-
Constructor Summary
Constructors Constructor Description BlockingMultiObserver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
blockingAwait(long timeout, java.util.concurrent.TimeUnit unit)
Block until the observer terminates and return true; return false if the wait times out.void
blockingConsume(Consumer<? super T> onSuccess, Consumer<? super java.lang.Throwable> onError, Action onComplete)
Blocks until the source completes and calls the appropriate callback.T
blockingGet()
Block until the latch is counted down then rethrow any exception received (wrapped if checked) or return the received value (null if none).T
blockingGet(T defaultValue)
Block until the latch is counted down then rethrow any exception received (wrapped if checked) or return the received value (the defaultValue if none).(package private) void
dispose()
void
onComplete()
Called once the deferred computation completes normally.void
onError(java.lang.Throwable e)
Notifies theSingleObserver
that theSingle
has experienced an error condition.void
onSubscribe(Disposable d)
Provides theSingleObserver
with the means of cancelling (disposing) the connection (channel) with the Single in both synchronous (from withinonSubscribe(Disposable)
itself) and asynchronous manner.void
onSuccess(T value)
Notifies theSingleObserver
with a single item and that theSingle
has finished sending push-based notifications.
-
-
-
Field Detail
-
value
T value
-
error
java.lang.Throwable error
-
upstream
Disposable upstream
-
cancelled
volatile boolean cancelled
-
-
Method Detail
-
dispose
void dispose()
-
onSubscribe
public void onSubscribe(Disposable d)
Description copied from interface:SingleObserver
Provides theSingleObserver
with the means of cancelling (disposing) the connection (channel) with the Single in both synchronous (from withinonSubscribe(Disposable)
itself) and asynchronous manner.- Specified by:
onSubscribe
in interfaceCompletableObserver
- Specified by:
onSubscribe
in interfaceMaybeObserver<T>
- Specified by:
onSubscribe
in interfaceSingleObserver<T>
- Parameters:
d
- the Disposable instance whoseDisposable.dispose()
can be called anytime to cancel the connection
-
onSuccess
public void onSuccess(T value)
Description copied from interface:SingleObserver
Notifies theSingleObserver
with a single item and that theSingle
has finished sending push-based notifications.The
Single
will not call this method if it callsSingleObserver.onError(java.lang.Throwable)
.- Specified by:
onSuccess
in interfaceMaybeObserver<T>
- Specified by:
onSuccess
in interfaceSingleObserver<T>
- Parameters:
value
- the item emitted by theSingle
-
onError
public void onError(java.lang.Throwable e)
Description copied from interface:SingleObserver
Notifies theSingleObserver
that theSingle
has experienced an error condition.If the
Single
calls this method, it will not thereafter callSingleObserver.onSuccess(T)
.- Specified by:
onError
in interfaceCompletableObserver
- Specified by:
onError
in interfaceMaybeObserver<T>
- Specified by:
onError
in interfaceSingleObserver<T>
- Parameters:
e
- the exception encountered by theSingle
-
onComplete
public void onComplete()
Description copied from interface:CompletableObserver
Called once the deferred computation completes normally.- Specified by:
onComplete
in interfaceCompletableObserver
- Specified by:
onComplete
in interfaceMaybeObserver<T>
-
blockingGet
public T blockingGet()
Block until the latch is counted down then rethrow any exception received (wrapped if checked) or return the received value (null if none).- Returns:
- the value received or null if no value received
-
blockingGet
public T blockingGet(T defaultValue)
Block until the latch is counted down then rethrow any exception received (wrapped if checked) or return the received value (the defaultValue if none).- Parameters:
defaultValue
- the default value to return if no value was received- Returns:
- the value received or defaultValue if no value received
-
blockingAwait
public boolean blockingAwait(long timeout, java.util.concurrent.TimeUnit unit)
Block until the observer terminates and return true; return false if the wait times out.- Parameters:
timeout
- the timeout valueunit
- the time unit- Returns:
- true if the observer terminated in time, false otherwise
-
blockingConsume
public void blockingConsume(Consumer<? super T> onSuccess, Consumer<? super java.lang.Throwable> onError, Action onComplete)
Blocks until the source completes and calls the appropriate callback.- Parameters:
onSuccess
- for a succeeding sourceonError
- for a failing sourceonComplete
- for an empty source
-
-