BlockingObservable
BlockingObservable is a variety of Observable that provides blocking operators. It can be
useful for testing and demo purposes, but is generally inappropriate for production applications (if you
think you need to use a BlockingObservable this is usually a sign that you should rethink your
design).
You construct a BlockingObservable from an Observable with from(Observable) or
Observable#toBlocking().
The documentation for this interface makes use of a form of marble diagram that has been modified to illustrate blocking operators. The following legend explains these marble diagrams:
| Modifier and Type | Field and Description |
|---|---|
| private final Observable | |
| pack-priv static final Object | ON_START
Constant to indicate the onStart method should be called. |
| pack-priv static final Object | SET_PRODUCER
Constant indicating the setProducer method should be called. |
| pack-priv static final Object | UNSUBSCRIBE
Indicates an unsubscription happened |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private T | Returns: the actual itemHelper method which handles the actual blocking for a single response. |
| public T | Returns: the first item emitted by thisBlockingObservableReturns the first item emitted by this |
| public T | Returns: the first item emitted by thisBlockingObservable that matches the predicatea predicate function to evaluate items emitted by this predicate)BlockingObservableReturns the first item emitted by this |
| public T | Returns: the first item emitted by thisBlockingObservable, or the default value if it emits no
itemsa default value to return if this defaultValue)BlockingObservable emits no itemsReturns the first item emitted by this |
| public T | Returns: the first item emitted by thisBlockingObservable that matches the predicate, or the
default value if this BlockingObservable emits no matching itemsa default value to return if this defaultValue, Func1<? super T, Boolean> BlockingObservable emits no matching itemsa predicate function to evaluate items emitted by this predicate)BlockingObservableReturns the first item emitted by this |
| public void | |
| public static < the observed value type T> BlockingObservable | Returns: aBlockingObservable version of othe o)Observable you want to convertConverts an |
| public Iterator | |
| public T | Returns: the last item emitted by thisBlockingObservableReturns the last item emitted by this |
| public T | Returns: the last item emitted by theBlockingObservable that matches the predicatea predicate function to evaluate items emitted by the predicate)BlockingObservableReturns the last item emitted by this |
| public T | Returns: the last item emitted by theBlockingObservable, or the default value if it emits no
itemsa default value to return if this defaultValue)BlockingObservable emits no itemsReturns the last item emitted by this |
| public T | Returns: the last item emitted by thisBlockingObservable that matches the predicate, or the
default value if it emits no matching itemsa default value to return if this defaultValue, Func1<? super T, Boolean> BlockingObservable emits no matching itemsa predicate function to evaluate items emitted by this predicate)BlockingObservableReturns the last item emitted by this |
| public Iterable | |
| public Iterable | Returns: anIterable that on each iteration returns the item that this BlockingObservable
has most recently emittedthe initial value that the initialValue)Iterable sequence will yield if this
BlockingObservable has not yet emitted an itemReturns an |
| public Iterable | |
| public T | Returns: the single item emitted by thisBlockingObservableIf this |
| public T | Returns: the single item emitted by thisBlockingObservable that matches the predicatea predicate function to evaluate items emitted by this predicate)BlockingObservableIf this |
| public T | Returns: the single item emitted by thisBlockingObservable, or the default value if it emits no
itemsa default value to return if this defaultValue)BlockingObservable emits no itemsIf this |
| public T | Returns: the single item emitted by theBlockingObservable that matches the predicate, or the
default value if no such items are emitteda default value to return if this defaultValue, Func1<? super T, Boolean> BlockingObservable emits no matching itemsa predicate function to evaluate items emitted by this predicate)BlockingObservableIf this |
| public void | subscribe()
Runs the source observable to a terminal event, ignoring any values and rethrowing any exception. |
| public void | |
| public void | subscribe(Subscriber<? super T>
the subscriber to forward events and calls to in the current thread subscriber)Subscribes to the source and calls the Subscriber methods on the current thread. |
| public void | |
| public void | |
| public void | subscribe(final Action1<? super T>
the callback action for each source value onNext, final Action1<? super Throwable> the callback action for an error event onError, final Action0 the callback action for the completion event. onCompleted)Subscribes to the source and calls the given actions on the current thread. |
| public Future | |
| public Iterable |
| o | back to summary |
|---|---|
| private final Observable<? extends T> o | |
| ON_START | back to summary |
|---|---|
| pack-priv static final Object ON_START Constant to indicate the onStart method should be called. | |
| SET_PRODUCER | back to summary |
|---|---|
| pack-priv static final Object SET_PRODUCER Constant indicating the setProducer method should be called. | |
| UNSUBSCRIBE | back to summary |
|---|---|
| pack-priv static final Object UNSUBSCRIBE Indicates an unsubscription happened | |
| BlockingObservable | back to summary |
|---|---|
| private BlockingObservable(Observable<? extends T> o) | |
| blockForSingle | back to summary |
|---|---|
| private T blockForSingle(final Observable<? extends T> observable) Helper method which handles the actual blocking for a single response.
If the
| |
| first | back to summary |
|---|---|
| public T first() Returns the first item emitted by this
| |
| first | back to summary |
|---|---|
| public T first(Func1<? super T, Boolean> predicate) Returns the first item emitted by this
| |
| firstOrDefault | back to summary |
|---|---|
| public T firstOrDefault(T defaultValue) Returns the first item emitted by this
| |
| firstOrDefault | back to summary |
|---|---|
| public T firstOrDefault(T defaultValue, Func1<? super T, Boolean> predicate) Returns the first item emitted by this
| |
| forEach | back to summary |
|---|---|
| public void forEach(final Action1<? super T> onNext) Invokes a method on each item emitted by this Note This will block even if the underlying Observable is asynchronous.
This is similar to The difference between this method and
| |
| from | back to summary |
|---|---|
| public static <T> BlockingObservable Converts an
| |
| getIterator | back to summary |
|---|---|
| public Iterator Returns an
| |
| last | back to summary |
|---|---|
| public T last() Returns the last item emitted by this
| |
| last | back to summary |
|---|---|
| public T last(final Func1<? super T, Boolean> predicate) Returns the last item emitted by this
| |
| lastOrDefault | back to summary |
|---|---|
| public T lastOrDefault(T defaultValue) Returns the last item emitted by this
| |
| lastOrDefault | back to summary |
|---|---|
| public T lastOrDefault(T defaultValue, Func1<? super T, Boolean> predicate) Returns the last item emitted by this
| |
| latest | back to summary |
|---|---|
| public Iterable Returns an
If this
Note also that an
| |
| mostRecent | back to summary |
|---|---|
| public Iterable Returns an
| |
| next | back to summary |
|---|---|
| public Iterable Returns an
| |
| single | back to summary |
|---|---|
| public T single() If this
| |
| single | back to summary |
|---|---|
| public T single(Func1<? super T, Boolean> predicate) If this
| |
| singleOrDefault | back to summary |
|---|---|
| public T singleOrDefault(T defaultValue) If this
| |
| singleOrDefault | back to summary |
|---|---|
| public T singleOrDefault(T defaultValue, Func1<? super T, Boolean> predicate) If this
| |
| subscribe | back to summary |
|---|---|
| public void subscribe() Runs the source observable to a terminal event, ignoring any values and rethrowing any exception.
| |
| subscribe | back to summary |
|---|---|
| public void subscribe(Observer<? super T> observer) Subscribes to the source and calls back the Observer methods on the current thread.
| |
| subscribe | back to summary |
|---|---|
| public void subscribe(Subscriber<? super T> subscriber) Subscribes to the source and calls the Subscriber methods on the current thread. The unsubscription and backpressure is composed through.
| |
| subscribe | back to summary |
|---|---|
| public void subscribe(final Action1<? super T> onNext) Subscribes to the source and calls the given action on the current thread and rethrows any exception wrapped into OnErrorNotImplementedException. The difference between this method and
| |
| subscribe | back to summary |
|---|---|
| public void subscribe(final Action1<? super T> onNext, final Action1<? super Throwable> onError) Subscribes to the source and calls the given actions on the current thread. | |
| subscribe | back to summary |
|---|---|
| public void subscribe(final Action1<? super T> onNext, final Action1<? super Throwable> onError, final Action0 onCompleted) Subscribes to the source and calls the given actions on the current thread. | |
| toFuture | back to summary |
|---|---|
| public Future Returns a
If
If the
| |
| toIterable | back to summary |
|---|---|
| public Iterable Converts this
| |