T - the type of item emitted by the
BlockingObservable
public final class BlockingObservable<T> extends Object
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.
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 | Method and Description |
|---|---|
T |
first()
Returns the first item emitted by this
BlockingObservable, or throws
NoSuchElementException if it emits no items.
|
T |
first(Func1
Returns the first item emitted by this
BlockingObservable that matches a predicate, or throws
NoSuchElementException if it emits no such item.
|
T |
firstOrDefault(T defaultValue)
Returns the first item emitted by this
BlockingObservable, or a default value if it emits no items.
|
T |
firstOrDefault(T defaultValue, Func1
Returns the first item emitted by this
BlockingObservable that matches a predicate, or a default value if it emits no such items.
|
void |
forEach(Action1
Invokes a method on each item emitted by this
BlockingObservable and blocks until the Observable completes.
|
static <T> BlockingObservable |
from(Observable
Converts an
Observable into a
BlockingObservable.
|
Iterator |
getIterator()
Returns an
Iterator that iterates over all items emitted by this
BlockingObservable.
|
T |
last()
Returns the last item emitted by this
BlockingObservable, or throws
NoSuchElementException if this
BlockingObservable emits no items.
|
T |
last(Func1
Returns the last item emitted by this
BlockingObservable that matches a predicate, or throws
NoSuchElementException if it emits no such items.
|
T |
lastOrDefault(T defaultValue)
Returns the last item emitted by this
BlockingObservable, or a default value if it emits no items.
|
T |
lastOrDefault(T defaultValue, Func1
Returns the last item emitted by this
BlockingObservable that matches a predicate, or a default value if it emits no such items.
|
Iterable |
latest()
Returns an
Iterable that returns the latest item emitted by this
BlockingObservable, waiting if necessary for one to become available.
|
Iterable |
mostRecent(T initialValue)
Returns an
Iterable that always returns the item most recently emitted by this
BlockingObservable.
|
Iterable |
next()
Returns an
Iterable that blocks until this
BlockingObservable emits another item, then returns that item.
|
T |
single()
If this
BlockingObservable completes after emitting a single item, return that item, otherwise throw a
NoSuchElementException.
|
T |
single(Func1
If this
BlockingObservable completes after emitting a single item that matches a given predicate, return that item, otherwise throw a
NoSuchElementException.
|
T |
singleOrDefault(T defaultValue)
If this
BlockingObservable completes after emitting a single item, return that item; if it emits more than one item, throw an
IllegalArgumentException; if it emits no items, return a default value.
|
T |
singleOrDefault(T defaultValue, Func1
If this
BlockingObservable completes after emitting a single item that matches a predicate, return that item; if it emits more than one such item, throw an
IllegalArgumentException; if it emits no items, return a default value.
|
Future |
toFuture()
Returns a
Future representing the single value emitted by this
BlockingObservable.
|
Iterable |
toIterable()
Converts this
BlockingObservable into an
Iterable.
|
public static <T> BlockingObservable<T> from(Observable <? extends T> o)
Observable into a
BlockingObservable.
o - the
Observable you want to convert
BlockingObservable version of
o
public void forEach(Action1<? super T> onNext)
BlockingObservable and blocks until the Observable completes.
Note: This will block even if the underlying Observable is asynchronous.
This is similar to Observable, but it blocks. Because it blocks it does not need the Observer or Observer methods. If the underlying Observable terminates with an error, rather than calling onError, this method will throw an exception.
onNext - the
Action1 to invoke for each item emitted by the
BlockingObservable
RuntimeException - if an error occurs
public Iterator<T> getIterator()
Iterator that can iterate over the items emitted by this
BlockingObservable
public T first()
BlockingObservable, or throws
NoSuchElementException if it emits no items.
BlockingObservable
NoSuchElementException - if this
BlockingObservable emits no items
public T first(Func1<? super T ,Boolean > predicate)
BlockingObservable that matches a predicate, or throws
NoSuchElementException if it emits no such item.
predicate - a predicate function to evaluate items emitted by this
BlockingObservable
BlockingObservable that matches the predicate
NoSuchElementException - if this
BlockingObservable emits no such items
public T firstOrDefault(T defaultValue)
BlockingObservable, or a default value if it emits no items.
defaultValue - a default value to return if this
BlockingObservable emits no items
BlockingObservable, or the default value if it emits no items
public T firstOrDefault(T defaultValue, Func1<? super T ,Boolean > predicate)
BlockingObservable that matches a predicate, or a default value if it emits no such items.
defaultValue - a default value to return if this
BlockingObservable emits no matching items
predicate - a predicate function to evaluate items emitted by this
BlockingObservable
BlockingObservable that matches the predicate, or the default value if this
BlockingObservable emits no matching items
public T last()
BlockingObservable, or throws
NoSuchElementException if this
BlockingObservable emits no items.

BlockingObservable
NoSuchElementException - if this
BlockingObservable emits no items
public T last(Func1<? super T ,Boolean > predicate)
BlockingObservable that matches a predicate, or throws
NoSuchElementException if it emits no such items.

predicate - a predicate function to evaluate items emitted by the
BlockingObservable
BlockingObservable that matches the predicate
NoSuchElementException - if this
BlockingObservable emits no items
public T lastOrDefault(T defaultValue)
BlockingObservable, or a default value if it emits no items.

defaultValue - a default value to return if this
BlockingObservable emits no items
BlockingObservable, or the default value if it emits no items
public T lastOrDefault(T defaultValue, Func1<? super T ,Boolean > predicate)
BlockingObservable that matches a predicate, or a default value if it emits no such items.

defaultValue - a default value to return if this
BlockingObservable emits no matching items
predicate - a predicate function to evaluate items emitted by this
BlockingObservable
BlockingObservable that matches the predicate, or the default value if it emits no matching items
public Iterable<T> mostRecent(T initialValue)
initialValue - the initial value that the
Iterable sequence will yield if this
BlockingObservable has not yet emitted an item
Iterable that on each iteration returns the item that this
BlockingObservable has most recently emitted
public Iterable<T> next()
Iterable that blocks until this
BlockingObservable emits another item, then returns that item.

Iterable that blocks upon each iteration until this
BlockingObservable emits a new item, whereupon the Iterable returns that item
public Iterable<T> latest()
Iterable that returns the latest item emitted by this
BlockingObservable, waiting if necessary for one to become available.
If this BlockingObservable produces items faster than Iterator.next takes them, onNext events might be skipped, but onError or onCompleted events are not.
Note also that an onNext directly followed by onCompleted might hide the onNext event.
BlockingObservable
public T single()
BlockingObservable completes after emitting a single item, return that item, otherwise throw a
NoSuchElementException.

BlockingObservable
public T single(Func1<? super T ,Boolean > predicate)
BlockingObservable completes after emitting a single item that matches a given predicate, return that item, otherwise throw a
NoSuchElementException.

predicate - a predicate function to evaluate items emitted by this
BlockingObservable
BlockingObservable that matches the predicate
public T singleOrDefault(T defaultValue)
BlockingObservable completes after emitting a single item, return that item; if it emits more than one item, throw an
IllegalArgumentException; if it emits no items, return a default value.

defaultValue - a default value to return if this
BlockingObservable emits no items
BlockingObservable, or the default value if it emits no items
public T singleOrDefault(T defaultValue, Func1<? super T ,Boolean > predicate)
BlockingObservable completes after emitting a single item that matches a predicate, return that item; if it emits more than one such item, throw an
IllegalArgumentException; if it emits no items, return a default value.

defaultValue - a default value to return if this
BlockingObservable emits no matching items
predicate - a predicate function to evaluate items emitted by this
BlockingObservable
BlockingObservable that matches the predicate, or the default value if no such items are emitted
public Future<T> toFuture()
Future representing the single value emitted by this
BlockingObservable.
If BlockingObservable emits more than one item, Future will receive an IllegalArgumentException. If BlockingObservable is empty, Future will receive an NoSuchElementException.
If the BlockingObservable may emit more than one item, use Observable.toList().toBlocking().toFuture().

Future that expects a single item to be emitted by this
BlockingObservable
public Iterable<T> toIterable()
Iterable version of this
BlockingObservable