T - public class BlockingObservable<T>
extends java.lang.Object
Observable that provides blocking operators, compatible with both threads and fibers.
You construct a BlockingObservable from an
Observable with from(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:
For more information see the Blocking Observable Operators page at the RxJava Wiki.
| Modifier and Type | Method and Description |
|---|---|
T |
first()
Returns the first item emitted by a specified
Observable, or
IllegalArgumentException if source contains no elements. |
T |
first(rx.functions.Func1<? super T,java.lang.Boolean> predicate)
Returns the first item emitted by a specified
Observable that
matches a predicate, or IllegalArgumentException if no such
item is emitted. |
T |
firstOrDefault(T defaultValue)
Returns the first item emitted by a specified
Observable, or a
default value if no items are emitted. |
T |
firstOrDefault(T defaultValue,
rx.functions.Func1<? super T,java.lang.Boolean> predicate)
Returns the first item emitted by a specified
Observable that
matches a predicate, or a default value if no such items are emitted. |
void |
forEach(rx.functions.Action1<? super T> onNext)
Invoke a method on each item emitted by the
Observable; block
until the Observable completes. |
static <T> BlockingObservable<T> |
from(rx.Observable<? extends T> o)
Convert an Observable into a BlockingObservable.
|
T |
last()
Returns the last item emitted by a specified
Observable, or
throws IllegalArgumentException if it emits no items. |
T |
last(rx.functions.Func1<? super T,java.lang.Boolean> predicate)
Returns the last item emitted by a specified
Observable that
matches a predicate, or throws IllegalArgumentException if
it emits no such items. |
T |
lastOrDefault(T defaultValue)
Returns the last item emitted by a specified
Observable, or a
default value if no items are emitted. |
T |
lastOrDefault(T defaultValue,
rx.functions.Func1<? super T,java.lang.Boolean> predicate)
Returns the last item emitted by a specified
Observable that
matches a predicate, or a default value if no such items are emitted. |
co.paralleluniverse.strands.channels.ReceivePort<T> |
latest()
Returns the latest item emitted by the underlying Observable, waiting if
necessary for one to become available.
|
co.paralleluniverse.strands.channels.ReceivePort<T> |
mostRecent(T initialValue)
Returns an
Iterable that always returns the item most recently
emitted by an Observable. |
co.paralleluniverse.strands.channels.ReceivePort<T> |
next()
Returns an
Iterable that blocks until the Observable emits another item, then returns that item. |
T |
single()
If the
Observable completes after emitting a single item, return
that item, otherwise throw an IllegalArgumentException. |
T |
single(rx.functions.Func1<? super T,java.lang.Boolean> predicate)
If the
Observable completes after emitting a single item that
matches a given predicate, return that item, otherwise throw an
IllegalArgumentException. |
T |
singleOrDefault(T defaultValue)
If the
Observable 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,
rx.functions.Func1<? super T,java.lang.Boolean> predicate)
If the
Observable 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. |
co.paralleluniverse.strands.channels.ReceivePort<T> |
toChannel()
Returns an
ReceivePort that receives all items emitted by a
specified Observable. |
java.util.concurrent.Future<T> |
toFuture()
Returns a
Future representing the single value emitted by an Observable. |
public static <T> BlockingObservable<T> from(rx.Observable<? extends T> o)
@Suspendable public void forEach(rx.functions.Action1<? super T> onNext)
Observable; block
until the Observable completes.
NOTE: This will block even if the Observable is asynchronous.
This is similar to Observable.subscribe(Subscriber), but it blocks.
Because it blocks it does not need the Observer.onCompleted() or Observer.onError(Throwable) methods.

onNext - the Action1 to invoke for every item emitted by the Observablejava.lang.RuntimeException - if an error occurspublic co.paralleluniverse.strands.channels.ReceivePort<T> toChannel()
ReceivePort that receives all items emitted by a
specified Observable.ReceivePort that receives all items emitted by a
specified Observable.@Suspendable public T first()
Observable, or
IllegalArgumentException if source contains no elements.Observablejava.lang.IllegalArgumentException - if source contains no elements@Suspendable public T first(rx.functions.Func1<? super T,java.lang.Boolean> predicate)
Observable that
matches a predicate, or IllegalArgumentException if no such
item is emitted.predicate - a predicate function to evaluate items emitted by the ObservableObservable that matches the
predicatejava.lang.IllegalArgumentException - if no such items are emitted@Suspendable public T firstOrDefault(T defaultValue)
Observable, or a
default value if no items are emitted.defaultValue - a default value to return if the Observable emits no itemsObservable, or the default
value if no items are emitted@Suspendable public T firstOrDefault(T defaultValue, rx.functions.Func1<? super T,java.lang.Boolean> predicate)
Observable that
matches a predicate, or a default value if no such items are emitted.defaultValue - a default value to return if the Observable emits no matching itemspredicate - a predicate function to evaluate items emitted by the ObservableObservable that matches the
predicate, or the default value if no matching items are emitted@Suspendable public T last()
Observable, or
throws IllegalArgumentException if it emits no items.

Observablejava.lang.IllegalArgumentException - if source contains no elements@Suspendable public T last(rx.functions.Func1<? super T,java.lang.Boolean> predicate)
Observable that
matches a predicate, or throws IllegalArgumentException if
it emits no such items.

predicate - a predicate function to evaluate items emitted by the ObservableObservable that matches the
predicatejava.lang.IllegalArgumentException - if no such items are emitted@Suspendable public T lastOrDefault(T defaultValue)
Observable, or a
default value if no items are emitted.

defaultValue - a default value to return if the Observable emits no itemsObservable, or the default
value if no items are emitted@Suspendable public T lastOrDefault(T defaultValue, rx.functions.Func1<? super T,java.lang.Boolean> predicate)
Observable that
matches a predicate, or a default value if no such items are emitted.

defaultValue - a default value to return if the Observable emits no matching itemspredicate - a predicate function to evaluate items emitted by the ObservableObservable that matches the
predicate, or the default value if no matching items are emittedpublic co.paralleluniverse.strands.channels.ReceivePort<T> mostRecent(T initialValue)
Iterable that always returns the item most recently
emitted by an Observable.

initialValue - the initial value that will be yielded by the Iterable sequence if the Observable has not yet emitted an itemIterable that on each iteration returns the item that
the Observable has most recently emittedpublic co.paralleluniverse.strands.channels.ReceivePort<T> next()
Iterable that blocks until the Observable emits another item, then returns that item.

Iterable that blocks upon each iteration until the Observable emits a new item, whereupon the Iterable returns that itempublic co.paralleluniverse.strands.channels.ReceivePort<T> latest()
If the underlying Observable produces items faster than the
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.
@Suspendable public T single()
Observable completes after emitting a single item, return
that item, otherwise throw an IllegalArgumentException.

Observable@Suspendable public T single(rx.functions.Func1<? super T,java.lang.Boolean> predicate)
Observable completes after emitting a single item that
matches a given predicate, return that item, otherwise throw an
IllegalArgumentException.

predicate - a predicate function to evaluate items emitted by the ObservableObservable that
matches the predicate@Suspendable public T singleOrDefault(T defaultValue)
Observable 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 the Observable emits no itemsObservable, or the default
value if no items are emitted@Suspendable public T singleOrDefault(T defaultValue, rx.functions.Func1<? super T,java.lang.Boolean> predicate)
Observable 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 the Observable emits no matching itemspredicate - a predicate function to evaluate items emitted by the ObservableObservable that matches
the predicate, or the default value if no such items are emittedpublic java.util.concurrent.Future<T> toFuture()
Future representing the single value emitted by an Observable.
toFuture() throws an exception if the Observable emits more
than one item. If the Observable may emit more than item, use toList().toFuture().

Future that expects a single item to be emitted by the source Observable