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 CountDownLatch
implements SingleObserver<T>, CompletableObserver, MaybeObserver<T>
A combined Observer that awaits the success or error signal via a CountDownLatch.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
blockingAwait
(long timeout, 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 Throwable> onError, Action onComplete) Blocks until the source completes and calls the appropriate callback.Block until the latch is counted down then rethrow any exception received (wrapped if checked) or return the received value (null if none).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
Called once the deferred computation completes normally.void
Notifies theSingleObserver
that theSingle
has experienced an error condition.void
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
Notifies theSingleObserver
with a single item and that theSingle
has finished sending push-based notifications.
-
Field Details
-
value
T value -
error
Throwable error -
upstream
Disposable upstream -
cancelled
volatile boolean cancelled
-
-
Constructor Details
-
BlockingMultiObserver
public BlockingMultiObserver()
-
-
Method Details
-
dispose
void dispose() -
onSubscribe
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
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
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
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
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
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 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
-