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 booleanblockingAwait(long timeout, java.util.concurrent.TimeUnit unit)Block until the observer terminates and return true; return false if the wait times out.voidblockingConsume(Consumer<? super T> onSuccess, Consumer<? super java.lang.Throwable> onError, Action onComplete)Blocks until the source completes and calls the appropriate callback.TblockingGet()Block until the latch is counted down then rethrow any exception received (wrapped if checked) or return the received value (null if none).TblockingGet(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) voiddispose()voidonComplete()Called once the deferred computation completes normally.voidonError(java.lang.Throwable e)Notifies theSingleObserverthat theSinglehas experienced an error condition.voidonSubscribe(Disposable d)Provides theSingleObserverwith the means of cancelling (disposing) the connection (channel) with the Single in both synchronous (from withinonSubscribe(Disposable)itself) and asynchronous manner.voidonSuccess(T value)Notifies theSingleObserverwith a single item and that theSinglehas 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:SingleObserverProvides theSingleObserverwith the means of cancelling (disposing) the connection (channel) with the Single in both synchronous (from withinonSubscribe(Disposable)itself) and asynchronous manner.- Specified by:
onSubscribein interfaceCompletableObserver- Specified by:
onSubscribein interfaceMaybeObserver<T>- Specified by:
onSubscribein 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:SingleObserverNotifies theSingleObserverwith a single item and that theSinglehas finished sending push-based notifications.The
Singlewill not call this method if it callsSingleObserver.onError(java.lang.Throwable).- Specified by:
onSuccessin interfaceMaybeObserver<T>- Specified by:
onSuccessin interfaceSingleObserver<T>- Parameters:
value- the item emitted by theSingle
-
onError
public void onError(java.lang.Throwable e)
Description copied from interface:SingleObserverNotifies theSingleObserverthat theSinglehas experienced an error condition.If the
Singlecalls this method, it will not thereafter callSingleObserver.onSuccess(T).- Specified by:
onErrorin interfaceCompletableObserver- Specified by:
onErrorin interfaceMaybeObserver<T>- Specified by:
onErrorin interfaceSingleObserver<T>- Parameters:
e- the exception encountered by theSingle
-
onComplete
public void onComplete()
Description copied from interface:CompletableObserverCalled once the deferred computation completes normally.- Specified by:
onCompletein interfaceCompletableObserver- Specified by:
onCompletein 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
-
-