T
- the type of the item emitted by the Singlepublic class Single<T>
extends java.lang.Object
Observable
for the
implementation of the Reactive Pattern for a stream or vector of values.
Single
behaves the same as Observable
except that it can only emit either a single successful
value, or an error (there is no "onComplete" notification as there is for Observable
)
Like an Observable
, a Single
is lazy, can be either "hot" or "cold", synchronous or
asynchronous.
The documentation for this class makes use of marble diagrams. The following legend explains these diagrams:
For more information see the ReactiveX documentation.
Modifier and Type | Class and Description |
---|---|
static interface |
Single.OnSubscribe<T>
Invoked when Single.execute is called.
|
static interface |
Single.Transformer<T,R>
Convenience type that allows a function to fluently transform a
Single into another Single via
compose(rx.Single.Transformer<? super T, ? extends R>) . |
Modifier | Constructor and Description |
---|---|
protected |
Single(Observable.OnSubscribe<T> f)
Deprecated.
1.2.1: Not recommended, use
Single(OnSubscribe) to avoid wrapping and
conversion between the Observable and Single protocols. |
protected |
Single(Single.OnSubscribe<T> f)
Creates a Single with a Function to execute when it is subscribed to (executed).
|
Modifier and Type | Method and Description |
---|---|
Single<T> |
cache()
Returns a Single that subscribes to this Single lazily, caches its success or error event
and replays it to all the downstream subscribers.
|
<R> Single<R> |
cast(java.lang.Class<R> klass)
Casts the success value of the current Single into the target type or signals a
ClassCastException if not compatible.
|
<R> Single<R> |
compose(Single.Transformer<? super T,? extends R> transformer)
Transform a Single by applying a particular Transformer function to it.
|
static <T> Observable<T> |
concat(Single<? extends T> t1,
Single<? extends T> t2)
Returns an Observable that emits the items emitted by two Singles, one after the other.
|
static <T> Observable<T> |
concat(Single<? extends T> t1,
Single<? extends T> t2,
Single<? extends T> t3)
Returns an Observable that emits the items emitted by three Singles, one after the other.
|
static <T> Observable<T> |
concat(Single<? extends T> t1,
Single<? extends T> t2,
Single<? extends T> t3,
Single<? extends T> t4)
Returns an Observable that emits the items emitted by four Singles, one after the other.
|
static <T> Observable<T> |
concat(Single<? extends T> t1,
Single<? extends T> t2,
Single<? extends T> t3,
Single<? extends T> t4,
Single<? extends T> t5)
Returns an Observable that emits the items emitted by five Singles, one after the other.
|
static <T> Observable<T> |
concat(Single<? extends T> t1,
Single<? extends T> t2,
Single<? extends T> t3,
Single<? extends T> t4,
Single<? extends T> t5,
Single<? extends T> t6)
Returns an Observable that emits the items emitted by six Singles, one after the other.
|
static <T> Observable<T> |
concat(Single<? extends T> t1,
Single<? extends T> t2,
Single<? extends T> t3,
Single<? extends T> t4,
Single<? extends T> t5,
Single<? extends T> t6,
Single<? extends T> t7)
Returns an Observable that emits the items emitted by seven Singles, one after the other.
|
static <T> Observable<T> |
concat(Single<? extends T> t1,
Single<? extends T> t2,
Single<? extends T> t3,
Single<? extends T> t4,
Single<? extends T> t5,
Single<? extends T> t6,
Single<? extends T> t7,
Single<? extends T> t8)
Returns an Observable that emits the items emitted by eight Singles, one after the other.
|
static <T> Observable<T> |
concat(Single<? extends T> t1,
Single<? extends T> t2,
Single<? extends T> t3,
Single<? extends T> t4,
Single<? extends T> t5,
Single<? extends T> t6,
Single<? extends T> t7,
Single<? extends T> t8,
Single<? extends T> t9)
Returns an Observable that emits the items emitted by nine Singles, one after the other.
|
Observable<T> |
concatWith(Single<? extends T> t1)
Returns an Observable that emits the item emitted by the source Single, then the item emitted by the
specified Single.
|
static <T> Single<T> |
create(Single.OnSubscribe<T> f)
Returns a Single that will execute the specified function when a
SingleSubscriber executes it or
a Subscriber subscribes to it. |
static <T> Single<T> |
defer(java.util.concurrent.Callable<Single<T>> singleFactory)
|
Single<T> |
delay(long delay,
java.util.concurrent.TimeUnit unit)
Returns a Single that emits the items emitted by the source Single shifted forward in time by a
specified delay.
|
Single<T> |
delay(long delay,
java.util.concurrent.TimeUnit unit,
Scheduler scheduler)
Returns a Single that emits the items emitted by the source Single shifted forward in time by a
specified delay.
|
Single<T> |
delaySubscription(Observable<?> other)
Returns a Single that delays the subscription to this Single
until the Observable completes.
|
Single<T> |
doAfterTerminate(Action0 action)
Registers an
Action0 to be called when this Single invokes either
SingleSubscriber.onSuccess(Object) onSuccess} or onError . |
Single<T> |
doOnEach(Action1<Notification<? extends T>> onNotification)
|
Single<T> |
doOnError(Action1<java.lang.Throwable> onError)
Modifies the source
Single so that it invokes an action if it calls onError . |
Single<T> |
doOnSubscribe(Action0 subscribe)
Modifies the source
Single so that it invokes the given action when it is subscribed from
its subscribers. |
Single<T> |
doOnSuccess(Action1<? super T> onSuccess)
Modifies the source
Single so that it invokes an action when it calls onSuccess . |
Single<T> |
doOnUnsubscribe(Action0 action)
Modifies the source
Single so that it invokes the given action when it is unsubscribed from
its subscribers. |
static <T> Single<T> |
error(java.lang.Throwable exception)
Returns a Single that invokes a subscriber's
onError method when the
subscriber subscribes to it. |
<R> Single<R> |
flatMap(Func1<? super T,? extends Single<? extends R>> func)
Returns a Single that is based on applying a specified function to the item emitted by the source Single,
where that function returns a Single.
|
Completable |
flatMapCompletable(Func1<? super T,? extends Completable> func)
Returns a
Completable that completes based on applying a specified function to the item emitted by the
source Completable , where that function returns a Completable . |
<R> Observable<R> |
flatMapObservable(Func1<? super T,? extends Observable<? extends R>> func)
Returns an Observable that emits items based on applying a specified function to the item emitted by the
source Observable, where that function returns an Observable.
|
static <T> Single<T> |
from(java.util.concurrent.Future<? extends T> future)
Converts a
Future into a Single . |
static <T> Single<T> |
from(java.util.concurrent.Future<? extends T> future,
long timeout,
java.util.concurrent.TimeUnit unit)
Converts a
Future into a Single , with a timeout on the Future. |
static <T> Single<T> |
from(java.util.concurrent.Future<? extends T> future,
Scheduler scheduler)
|
static <T> Single<T> |
fromCallable(java.util.concurrent.Callable<? extends T> func)
Returns a
Single that invokes passed function and emits its result for each new Observer that subscribes. |
static <T> Single<T> |
fromEmitter(Action1<SingleEmitter<T>> producer)
Provides an API (in a cold Single) that bridges the Single-reactive world
with the callback-based world.
|
static <T> Single<T> |
just(T value)
Returns a
Single that emits a specified item. |
<R> Single<R> |
lift(Observable.Operator<? extends R,? super T> lift)
Lifts a function to the current Single and returns a new Single that when subscribed to will pass the
values of the current Single through the Operator function.
|
<R> Single<R> |
map(Func1<? super T,? extends R> func)
Returns a Single that applies a specified function to the item emitted by the source Single and
emits the result of this function application.
|
static <T> Observable<T> |
merge(Observable<? extends Single<? extends T>> sources)
Merges all Singles emitted by the Observable and runs them together until the source
Observable and all inner Singles complete normally.
|
static <T> Observable<T> |
merge(Observable<? extends Single<? extends T>> sources,
int maxConcurrency)
Merges the Singles emitted by the Observable and runs up to the given number of them together at a time,
until the Observable and all inner Singles terminate.
|
static <T> Single<T> |
merge(Single<? extends Single<? extends T>> source)
Flattens a
Single that emits a Single into a single Single that emits the item
emitted by the nested Single , without any transformation. |
static <T> Observable<T> |
merge(Single<? extends T> t1,
Single<? extends T> t2)
Flattens two Singles into a single Observable, without any transformation.
|
static <T> Observable<T> |
merge(Single<? extends T> t1,
Single<? extends T> t2,
Single<? extends T> t3)
Flattens three Singles into a single Observable, without any transformation.
|
static <T> Observable<T> |
merge(Single<? extends T> t1,
Single<? extends T> t2,
Single<? extends T> t3,
Single<? extends T> t4)
Flattens four Singles into a single Observable, without any transformation.
|
static <T> Observable<T> |
merge(Single<? extends T> t1,
Single<? extends T> t2,
Single<? extends T> t3,
Single<? extends T> t4,
Single<? extends T> t5)
Flattens five Singles into a single Observable, without any transformation.
|
static <T> Observable<T> |
merge(Single<? extends T> t1,
Single<? extends T> t2,
Single<? extends T> t3,
Single<? extends T> t4,
Single<? extends T> t5,
Single<? extends T> t6)
Flattens six Singles into a single Observable, without any transformation.
|
static <T> Observable<T> |
merge(Single<? extends T> t1,
Single<? extends T> t2,
Single<? extends T> t3,
Single<? extends T> t4,
Single<? extends T> t5,
Single<? extends T> t6,
Single<? extends T> t7)
Flattens seven Singles into a single Observable, without any transformation.
|
static <T> Observable<T> |
merge(Single<? extends T> t1,
Single<? extends T> t2,
Single<? extends T> t3,
Single<? extends T> t4,
Single<? extends T> t5,
Single<? extends T> t6,
Single<? extends T> t7,
Single<? extends T> t8)
Flattens eight Singles into a single Observable, without any transformation.
|
static <T> Observable<T> |
merge(Single<? extends T> t1,
Single<? extends T> t2,
Single<? extends T> t3,
Single<? extends T> t4,
Single<? extends T> t5,
Single<? extends T> t6,
Single<? extends T> t7,
Single<? extends T> t8,
Single<? extends T> t9)
Flattens nine Singles into a single Observable, without any transformation.
|
static <T> Observable<T> |
mergeDelayError(Observable<? extends Single<? extends T>> sources)
Merges all Singles emitted by the Observable and runs them together,
delaying errors from them and the Observable, until the source
Observable and all inner Singles complete normally.
|
static <T> Observable<T> |
mergeDelayError(Observable<? extends Single<? extends T>> sources,
int maxConcurrency)
Merges the Singles emitted by the Observable and runs up to the given number of them together at a time,
delaying errors from them and the Observable, until the Observable and all inner Singles terminate.
|
Observable<T> |
mergeWith(Single<? extends T> t1)
Flattens this and another Single into a single Observable, without any transformation.
|
Single<T> |
observeOn(Scheduler scheduler)
Modifies a Single to emit its item (or notify of its error) on a specified
Scheduler ,
asynchronously. |
Single<T> |
onErrorResumeNext(Func1<java.lang.Throwable,? extends Single<? extends T>> resumeFunctionInCaseOfError)
Instructs a Single to pass control to another Single rather than invoking
Observer.onError(Throwable) if it encounters an error. |
Single<T> |
onErrorResumeNext(Single<? extends T> resumeSingleInCaseOfError)
Instructs a Single to pass control to another Single rather than invoking
Observer.onError(Throwable) if it encounters an error. |
Single<T> |
onErrorReturn(Func1<java.lang.Throwable,? extends T> resumeFunction)
Instructs a Single to emit an item (returned by a specified function) rather than invoking
onError if it encounters an error. |
Single<T> |
retry()
Returns a Single that mirrors the source Single, resubscribing to it if it calls
onError
(infinite retry count). |
Single<T> |
retry(Func2<java.lang.Integer,java.lang.Throwable,java.lang.Boolean> predicate)
Returns a Single that mirrors the source Single, resubscribing to it if it calls
onError
and the predicate returns true for that specific exception and retry count. |
Single<T> |
retry(long count)
Returns a Single that mirrors the source Single, resubscribing to it if it calls
onError
up to a specified number of retries. |
Single<T> |
retryWhen(Func1<Observable<? extends java.lang.Throwable>,? extends Observable<?>> notificationHandler)
Returns a Single that emits the same values as the source Single with the exception of an
onError . |
Subscription |
subscribe()
Subscribes to a Single but ignore its emission or notification.
|
Subscription |
subscribe(Action1<? super T> onSuccess)
Subscribes to a Single and provides a callback to handle the item it emits.
|
Subscription |
subscribe(Action1<? super T> onSuccess,
Action1<java.lang.Throwable> onError)
Subscribes to a Single and provides callbacks to handle the item it emits or any error notification it
issues.
|
Subscription |
subscribe(Observer<? super T> observer)
Subscribes an Observer to this single and returns a Subscription that allows
unsubscription.
|
Subscription |
subscribe(SingleSubscriber<? super T> te)
Subscribes to a Single and provides a
SingleSubscriber that implements functions to handle the
item the Single emits or any error notification it issues. |
Subscription |
subscribe(Subscriber<? super T> subscriber)
Subscribes to a Single and provides a Subscriber that implements functions to handle the item the Single
emits or any error notification it issues.
|
Single<T> |
subscribeOn(Scheduler scheduler)
Asynchronously subscribes subscribers to this Single on the specified
Scheduler . |
Single<T> |
takeUntil(Completable other)
Returns a Single that emits the item emitted by the source Single until a Completable terminates.
|
<E> Single<T> |
takeUntil(Observable<? extends E> other)
Returns a Single that emits the item emitted by the source Single until an Observable emits an item.
|
<E> Single<T> |
takeUntil(Single<? extends E> other)
Returns a Single that emits the item emitted by the source Single until a second Single emits an item.
|
AssertableSubscriber<T> |
test()
Creates an AssertableSubscriber that requests
Long.MAX_VALUE and subscribes
it to this Observable. |
Single<T> |
timeout(long timeout,
java.util.concurrent.TimeUnit timeUnit)
Returns a Single that mirrors the source Single but applies a timeout policy for its emitted item.
|
Single<T> |
timeout(long timeout,
java.util.concurrent.TimeUnit timeUnit,
Scheduler scheduler)
Returns a Single that mirrors the source Single but applies a timeout policy for its emitted item, where
this policy is governed on a specified Scheduler.
|
Single<T> |
timeout(long timeout,
java.util.concurrent.TimeUnit timeUnit,
Single<? extends T> other)
Returns a Single that mirrors the source Single but applies a timeout policy for its emitted item.
|
Single<T> |
timeout(long timeout,
java.util.concurrent.TimeUnit timeUnit,
Single<? extends T> other,
Scheduler scheduler)
Returns a Single that mirrors the source Single but applies a timeout policy for its emitted item, using
a specified Scheduler.
|
<R> R |
to(Func1<? super Single<T>,R> converter)
Calls the specified converter function during assembly time and returns its resulting value.
|
BlockingSingle<T> |
toBlocking()
Converts a Single into a
BlockingSingle (a Single with blocking operators). |
Completable |
toCompletable()
Returns a
Completable that discards result of the Single (similar to
Observable.ignoreElements() ) and calls onCompleted when this source Single calls
onSuccess . |
Observable<T> |
toObservable()
Converts this Single into an
Observable . |
Subscription |
unsafeSubscribe(Subscriber<? super T> subscriber)
Subscribes to a Single and invokes the
Single.OnSubscribe function without any contract protection,
error handling, unsubscribe, or execution hooks. |
Single<T> |
unsubscribeOn(Scheduler scheduler)
Returns a Single which makes sure when a subscriber cancels the subscription,
the dispose is called on the specified scheduler
|
static <T,Resource> |
using(Func0<Resource> resourceFactory,
Func1<? super Resource,? extends Single<? extends T>> singleFactory,
Action1<? super Resource> disposeAction)
Constructs a Single that creates a dependent resource object which is disposed of on unsubscription.
|
static <T,Resource> |
using(Func0<Resource> resourceFactory,
Func1<? super Resource,? extends Single<? extends T>> singleFactory,
Action1<? super Resource> disposeAction,
boolean disposeEagerly)
Constructs a Single that creates a dependent resource object which is disposed of just before
termination if you have set
disposeEagerly to true and unsubscription does not occur
before termination. |
static <R> Single<R> |
zip(java.lang.Iterable<? extends Single<?>> singles,
FuncN<? extends R> zipFunction)
Returns a Single that emits the result of specified combiner function applied to combination of
items emitted, in sequence, by an Iterable of other Singles.
|
static <T1,T2,R> Single<R> |
zip(Single<? extends T1> s1,
Single<? extends T2> s2,
Func2<? super T1,? super T2,? extends R> zipFunction)
Returns a Single that emits the results of a specified combiner function applied to two items emitted by
two other Singles.
|
static <T1,T2,T3,R> |
zip(Single<? extends T1> s1,
Single<? extends T2> s2,
Single<? extends T3> s3,
Func3<? super T1,? super T2,? super T3,? extends R> zipFunction)
Returns a Single that emits the results of a specified combiner function applied to three items emitted
by three other Singles.
|
static <T1,T2,T3,T4,R> |
zip(Single<? extends T1> s1,
Single<? extends T2> s2,
Single<? extends T3> s3,
Single<? extends T4> s4,
Func4<? super T1,? super T2,? super T3,? super T4,? extends R> zipFunction)
Returns an Observable that emits the results of a specified combiner function applied to four items
emitted by four other Singles.
|
static <T1,T2,T3,T4,T5,R> |
zip(Single<? extends T1> s1,
Single<? extends T2> s2,
Single<? extends T3> s3,
Single<? extends T4> s4,
Single<? extends T5> s5,
Func5<? super T1,? super T2,? super T3,? super T4,? super T5,? extends R> zipFunction)
Returns an Observable that emits the results of a specified combiner function applied to five items
emitted by five other Singles.
|
static <T1,T2,T3,T4,T5,T6,R> |
zip(Single<? extends T1> s1,
Single<? extends T2> s2,
Single<? extends T3> s3,
Single<? extends T4> s4,
Single<? extends T5> s5,
Single<? extends T6> s6,
Func6<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? extends R> zipFunction)
Returns an Observable that emits the results of a specified combiner function applied to six items
emitted by six other Singles.
|
static <T1,T2,T3,T4,T5,T6,T7,R> |
zip(Single<? extends T1> s1,
Single<? extends T2> s2,
Single<? extends T3> s3,
Single<? extends T4> s4,
Single<? extends T5> s5,
Single<? extends T6> s6,
Single<? extends T7> s7,
Func7<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? super T7,? extends R> zipFunction)
Returns an Observable that emits the results of a specified combiner function applied to seven items
emitted by seven other Singles.
|
static <T1,T2,T3,T4,T5,T6,T7,T8,R> |
zip(Single<? extends T1> s1,
Single<? extends T2> s2,
Single<? extends T3> s3,
Single<? extends T4> s4,
Single<? extends T5> s5,
Single<? extends T6> s6,
Single<? extends T7> s7,
Single<? extends T8> s8,
Func8<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? super T7,? super T8,? extends R> zipFunction)
Returns an Observable that emits the results of a specified combiner function applied to eight items
emitted by eight other Singles.
|
static <T1,T2,T3,T4,T5,T6,T7,T8,T9,R> |
zip(Single<? extends T1> s1,
Single<? extends T2> s2,
Single<? extends T3> s3,
Single<? extends T4> s4,
Single<? extends T5> s5,
Single<? extends T6> s6,
Single<? extends T7> s7,
Single<? extends T8> s8,
Single<? extends T9> s9,
Func9<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? super T7,? super T8,? super T9,? extends R> zipFunction)
Returns an Observable that emits the results of a specified combiner function applied to nine items
emitted by nine other Singles.
|
<T2,R> Single<R> |
zipWith(Single<? extends T2> other,
Func2<? super T,? super T2,? extends R> zipFunction)
Returns a Single that emits the result of applying a specified function to the pair of items emitted by
the source Single and another specified Single.
|
protected Single(Single.OnSubscribe<T> f)
Note: Use create(OnSubscribe)
to create a Single, instead of this constructor,
unless you specifically have a need for inheritance.
f
- f
to be executed when execute(SingleSubscriber)
or
subscribe(Subscriber)
is called@Deprecated protected Single(Observable.OnSubscribe<T> f)
Single(OnSubscribe)
to avoid wrapping and
conversion between the Observable and Single protocols.
Note: Use create(OnSubscribe)
to create a Single, instead of this constructor,
unless you specifically have a need for inheritance.
f
- f
to be executed when execute(SingleSubscriber)
or
subscribe(Subscriber)
is calledpublic static <T> Single<T> create(Single.OnSubscribe<T> f)
SingleSubscriber
executes it or
a Subscriber
subscribes to it.
Write the function you pass to create
so that it behaves as a Single: It should invoke the
SingleSubscriber onSuccess
and/or
onError
methods appropriately.
A well-formed Single must invoke either the SingleSubscriber's onSuccess
method exactly once or
its onError
method exactly once.
create
does not operate by default on a particular Scheduler
.T
- the type of the item that this Single emitsf
- a function that accepts an SingleSubscriber<T>
, and invokes its onSuccess
or
onError
methods as appropriateSubscriber
subscribes to it, will execute the specified functionpublic final <R> Single<R> lift(Observable.Operator<? extends R,? super T> lift)
In other words, this allows chaining TaskExecutors together on a Single for acting on the values within the Single.
task.map(...).filter(...).lift(new OperatorA()).lift(new OperatorB(...)).subscribe()
If the operator you are creating is designed to act on the item emitted by a source Single, use
lift
. If your operator is designed to transform the source Single as a whole (for instance, by
applying a particular set of existing RxJava operators to it) use compose(rx.Single.Transformer<? super T, ? extends R>)
.
lift
does not operate by default on a particular Scheduler
.R
- the downstream's value type (output)lift
- the Operator that implements the Single-operating function to be applied to the source Singlepublic <R> Single<R> compose(Single.Transformer<? super T,? extends R> transformer)
This method operates on the Single itself whereas lift(rx.Observable.Operator<? extends R, ? super T>)
operates on the Single's Subscribers or
Observers.
If the operator you are creating is designed to act on the individual item emitted by a Single, use
lift(rx.Observable.Operator<? extends R, ? super T>)
. If your operator is designed to transform the source Single as a whole (for instance, by
applying a particular set of existing RxJava operators to it) use compose
.
compose
does not operate by default on a particular Scheduler
.R
- the value type of the single returned by the transformer functiontransformer
- implements the function that transforms the source Single@Experimental public final <R> Single<R> cast(java.lang.Class<R> klass)
cast
does not operate by default on a particular Scheduler
.R
- the target typeklass
- the type token to use for casting the success result from the current Singlepublic static <T> Observable<T> concat(Single<? extends T> t1, Single<? extends T> t2)
concat
does not operate by default on a particular Scheduler
.T
- the common value typet1
- a Single to be concatenatedt2
- a Single to be concatenatedpublic static <T> Observable<T> concat(Single<? extends T> t1, Single<? extends T> t2, Single<? extends T> t3)
concat
does not operate by default on a particular Scheduler
.T
- the common value typet1
- a Single to be concatenatedt2
- a Single to be concatenatedt3
- a Single to be concatenatedpublic static <T> Observable<T> concat(Single<? extends T> t1, Single<? extends T> t2, Single<? extends T> t3, Single<? extends T> t4)
concat
does not operate by default on a particular Scheduler
.T
- the common value typet1
- a Single to be concatenatedt2
- a Single to be concatenatedt3
- a Single to be concatenatedt4
- a Single to be concatenatedpublic static <T> Observable<T> concat(Single<? extends T> t1, Single<? extends T> t2, Single<? extends T> t3, Single<? extends T> t4, Single<? extends T> t5)
concat
does not operate by default on a particular Scheduler
.T
- the common value typet1
- a Single to be concatenatedt2
- a Single to be concatenatedt3
- a Single to be concatenatedt4
- a Single to be concatenatedt5
- a Single to be concatenatedpublic static <T> Observable<T> concat(Single<? extends T> t1, Single<? extends T> t2, Single<? extends T> t3, Single<? extends T> t4, Single<? extends T> t5, Single<? extends T> t6)
concat
does not operate by default on a particular Scheduler
.T
- the common value typet1
- a Single to be concatenatedt2
- a Single to be concatenatedt3
- a Single to be concatenatedt4
- a Single to be concatenatedt5
- a Single to be concatenatedt6
- a Single to be concatenatedpublic static <T> Observable<T> concat(Single<? extends T> t1, Single<? extends T> t2, Single<? extends T> t3, Single<? extends T> t4, Single<? extends T> t5, Single<? extends T> t6, Single<? extends T> t7)
concat
does not operate by default on a particular Scheduler
.T
- the common value typet1
- a Single to be concatenatedt2
- a Single to be concatenatedt3
- a Single to be concatenatedt4
- a Single to be concatenatedt5
- a Single to be concatenatedt6
- a Single to be concatenatedt7
- a Single to be concatenatedpublic static <T> Observable<T> concat(Single<? extends T> t1, Single<? extends T> t2, Single<? extends T> t3, Single<? extends T> t4, Single<? extends T> t5, Single<? extends T> t6, Single<? extends T> t7, Single<? extends T> t8)
concat
does not operate by default on a particular Scheduler
.T
- the common value typet1
- a Single to be concatenatedt2
- a Single to be concatenatedt3
- a Single to be concatenatedt4
- a Single to be concatenatedt5
- a Single to be concatenatedt6
- a Single to be concatenatedt7
- a Single to be concatenatedt8
- a Single to be concatenatedpublic static <T> Observable<T> concat(Single<? extends T> t1, Single<? extends T> t2, Single<? extends T> t3, Single<? extends T> t4, Single<? extends T> t5, Single<? extends T> t6, Single<? extends T> t7, Single<? extends T> t8, Single<? extends T> t9)
concat
does not operate by default on a particular Scheduler
.T
- the common value typet1
- a Single to be concatenatedt2
- a Single to be concatenatedt3
- a Single to be concatenatedt4
- a Single to be concatenatedt5
- a Single to be concatenatedt6
- a Single to be concatenatedt7
- a Single to be concatenatedt8
- a Single to be concatenatedt9
- a Single to be concatenatedpublic static <T> Single<T> error(java.lang.Throwable exception)
onError
method when the
subscriber subscribes to it.
error
does not operate by default on a particular Scheduler
.T
- the type of the item (ostensibly) emitted by the Singleexception
- the particular Throwable to pass to onError
onError
method when
the subscriber subscribes to itpublic static <T> Single<T> from(java.util.concurrent.Future<? extends T> future)
Future
into a Single
.
You can convert any object that supports the Future
interface into a Single that emits the return
value of the Future.get()
method of that object, by passing the object into the from
method.
Important note: This Single is blocking; you cannot unsubscribe from it.
from
does not operate by default on a particular Scheduler
.T
- the type of object that the Future
returns, and also the type of item to be emitted by
the resulting Single
future
- the source Future
Single
that emits the item from the source Future
public static <T> Single<T> from(java.util.concurrent.Future<? extends T> future, long timeout, java.util.concurrent.TimeUnit unit)
Future
into a Single
, with a timeout on the Future.
You can convert any object that supports the Future
interface into a Single
that emits
the return value of the Future.get()
method of that object, by passing the object into the
from
method.
Important note: This Single
is blocking; you cannot unsubscribe from it.
from
does not operate by default on a particular Scheduler
.T
- the type of object that the Future
returns, and also the type of item to be emitted by
the resulting Single
future
- the source Future
timeout
- the maximum time to wait before calling get
unit
- the TimeUnit
of the timeout
argumentSingle
that emits the item from the source Future
public static <T> Single<T> from(java.util.concurrent.Future<? extends T> future, Scheduler scheduler)
Future
, operating on a specified Scheduler
, into a Single
.
You can convert any object that supports the Future
interface into a Single
that emits
the return value of the Future.get()
method of that object, by passing the object into the
from
method.
Scheduler
this operator will useT
- the type of object that the Future
returns, and also the type of item to be emitted by
the resulting Single
future
- the source Future
scheduler
- the Scheduler
to wait for the Future on. Use a Scheduler such as
Schedulers.io()
that can block and wait on the FutureSingle
that emits the item from the source Future
public static <T> Single<T> fromCallable(java.util.concurrent.Callable<? extends T> func)
Single
that invokes passed function and emits its result for each new Observer that subscribes.
Allows you to defer execution of passed function until Observer subscribes to the Single
.
It makes passed function "lazy".
Result of the function invocation will be emitted by the Single
.
fromCallable
does not operate by default on a particular Scheduler
.public static <T> Single<T> fromEmitter(Action1<SingleEmitter<T>> producer)
The SingleEmitter
allows registering a callback for
cancellation/unsubscription of a resource.
Example:
Single.fromEmitter(emitter -> {
Callback listener = new Callback() {
@Override
public void onEvent(Event e) {
emitter.onSuccess(e.getData());
}
@Override
public void onFailure(Exception e) {
emitter.onError(e);
}
};
AutoCloseable c = api.someMethod(listener);
emitter.setCancellation(c::close);
});
All of the SingleEmitter's methods are thread-safe and ensure the Single's protocol are held.
History: 1.2.3 - experimental
T
- the success value typeproducer
- the callback invoked for each incoming SingleSubscriberpublic static <T> Single<T> just(T value)
Single
that emits a specified item.
To convert any object into a Single
that emits that object, pass that object into the
just
method.
just
does not operate by default on a particular Scheduler
.T
- the type of that itemvalue
- the item to emitSingle
that emits value
public static <T> Single<T> merge(Single<? extends Single<? extends T>> source)
Single
that emits a Single
into a single Single
that emits the item
emitted by the nested Single
, without any transformation.
merge
does not operate by default on a particular Scheduler
.T
- the value type of the sources and the outputsource
- a Single
that emits a Single
Single
that emits the item that is the result of flattening the Single
emitted
by source
public static <T> Observable<T> merge(Single<? extends T> t1, Single<? extends T> t2)
You can combine items emitted by multiple Singles so that they appear as a single Observable, by
using the merge
method.
merge
does not operate by default on a particular Scheduler
.T
- the common value typet1
- a Single to be mergedt2
- a Single to be mergedpublic static <T> Observable<T> merge(Single<? extends T> t1, Single<? extends T> t2, Single<? extends T> t3)
You can combine items emitted by multiple Singles so that they appear as a single Observable, by using
the merge
method.
merge
does not operate by default on a particular Scheduler
.T
- the common value typet1
- a Single to be mergedt2
- a Single to be mergedt3
- a Single to be mergedpublic static <T> Observable<T> merge(Single<? extends T> t1, Single<? extends T> t2, Single<? extends T> t3, Single<? extends T> t4)
You can combine items emitted by multiple Singles so that they appear as a single Observable, by using
the merge
method.
merge
does not operate by default on a particular Scheduler
.T
- the common value typet1
- a Single to be mergedt2
- a Single to be mergedt3
- a Single to be mergedt4
- a Single to be mergedpublic static <T> Observable<T> merge(Single<? extends T> t1, Single<? extends T> t2, Single<? extends T> t3, Single<? extends T> t4, Single<? extends T> t5)
You can combine items emitted by multiple Singles so that they appear as a single Observable, by using
the merge
method.
merge
does not operate by default on a particular Scheduler
.T
- the common value typet1
- a Single to be mergedt2
- a Single to be mergedt3
- a Single to be mergedt4
- a Single to be mergedt5
- a Single to be mergedpublic static <T> Observable<T> merge(Single<? extends T> t1, Single<? extends T> t2, Single<? extends T> t3, Single<? extends T> t4, Single<? extends T> t5, Single<? extends T> t6)
You can combine items emitted by multiple Singles so that they appear as a single Observable, by using
the merge
method.
merge
does not operate by default on a particular Scheduler
.T
- the common value typet1
- a Single to be mergedt2
- a Single to be mergedt3
- a Single to be mergedt4
- a Single to be mergedt5
- a Single to be mergedt6
- a Single to be mergedpublic static <T> Observable<T> merge(Single<? extends T> t1, Single<? extends T> t2, Single<? extends T> t3, Single<? extends T> t4, Single<? extends T> t5, Single<? extends T> t6, Single<? extends T> t7)
You can combine items emitted by multiple Singles so that they appear as a single Observable, by using
the merge
method.
merge
does not operate by default on a particular Scheduler
.T
- the common value typet1
- a Single to be mergedt2
- a Single to be mergedt3
- a Single to be mergedt4
- a Single to be mergedt5
- a Single to be mergedt6
- a Single to be mergedt7
- a Single to be mergedpublic static <T> Observable<T> merge(Single<? extends T> t1, Single<? extends T> t2, Single<? extends T> t3, Single<? extends T> t4, Single<? extends T> t5, Single<? extends T> t6, Single<? extends T> t7, Single<? extends T> t8)
You can combine items emitted by multiple Singles so that they appear as a single Observable, by using
the merge
method.
merge
does not operate by default on a particular Scheduler
.T
- the common value typet1
- a Single to be mergedt2
- a Single to be mergedt3
- a Single to be mergedt4
- a Single to be mergedt5
- a Single to be mergedt6
- a Single to be mergedt7
- a Single to be mergedt8
- a Single to be mergedpublic static <T> Observable<T> merge(Single<? extends T> t1, Single<? extends T> t2, Single<? extends T> t3, Single<? extends T> t4, Single<? extends T> t5, Single<? extends T> t6, Single<? extends T> t7, Single<? extends T> t8, Single<? extends T> t9)
You can combine items emitted by multiple Singles so that they appear as a single Observable, by using
the merge
method.
merge
does not operate by default on a particular Scheduler
.T
- the common value typet1
- a Single to be mergedt2
- a Single to be mergedt3
- a Single to be mergedt4
- a Single to be mergedt5
- a Single to be mergedt6
- a Single to be mergedt7
- a Single to be mergedt8
- a Single to be mergedt9
- a Single to be mergedpublic static <T> Observable<T> merge(Observable<? extends Single<? extends T>> sources)
merge
does not operate by default on a particular Scheduler
.History: 1.2.7 - experimental
T
- the value type of the inner Singles and the resulting Observablesources
- the Observable that emits Singles to be mergedmerge(Observable, int)
,
mergeDelayError(Observable)
,
mergeDelayError(Observable, int)
public static <T> Observable<T> merge(Observable<? extends Single<? extends T>> sources, int maxConcurrency)
flatMapSingle
does not operate by default on a particular Scheduler
.History: 1.2.7 - experimental
T
- the value type of the inner Singles and the resulting Observablesources
- the Observable that emits Singles to be mergedmaxConcurrency
- the maximum number of inner Singles to run at a timepublic static <T> Observable<T> mergeDelayError(Observable<? extends Single<? extends T>> sources)
merge
does not operate by default on a particular Scheduler
.History: 1.2.7 - experimental
T
- the value type of the inner Singles and the resulting Observablesources
- the Observable that emits Singles to be mergedmergeDelayError(Observable, int)
,
merge(Observable)
,
merge(Observable, int)
public static <T> Observable<T> mergeDelayError(Observable<? extends Single<? extends T>> sources, int maxConcurrency)
flatMapSingle
does not operate by default on a particular Scheduler
.History: 1.2.7 - experimental
T
- the value type of the inner Singles and the resulting Observablesources
- the Observable that emits Singles to be mergedmaxConcurrency
- the maximum number of inner Singles to run at a timepublic static <T1,T2,R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, Func2<? super T1,? super T2,? extends R> zipFunction)
zip
does not operate by default on a particular Scheduler
.T1
- the first source Single's value typeT2
- the second source Single's value typeR
- the result value types1
- the first source Singles2
- a second source SinglezipFunction
- a function that, when applied to the item emitted by each of the source Singles, results in an
item that will be emitted by the resulting Singlepublic static <T1,T2,T3,R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Func3<? super T1,? super T2,? super T3,? extends R> zipFunction)
zip
does not operate by default on a particular Scheduler
.T1
- the first source Single's value typeT2
- the second source Single's value typeT3
- the third source Single's value typeR
- the result value types1
- the first source Singles2
- a second source Singles3
- a third source SinglezipFunction
- a function that, when applied to the item emitted by each of the source Singles, results in an
item that will be emitted by the resulting Singlepublic static <T1,T2,T3,T4,R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Single<? extends T4> s4, Func4<? super T1,? super T2,? super T3,? super T4,? extends R> zipFunction)
zip
does not operate by default on a particular Scheduler
.T1
- the first source Single's value typeT2
- the second source Single's value typeT3
- the third source Single's value typeT4
- the fourth source Single's value typeR
- the result value types1
- the first source Singles2
- a second source Singles3
- a third source Singles4
- a fourth source SinglezipFunction
- a function that, when applied to the item emitted by each of the source Singles, results in an
item that will be emitted by the resulting Singlepublic static <T1,T2,T3,T4,T5,R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Single<? extends T4> s4, Single<? extends T5> s5, Func5<? super T1,? super T2,? super T3,? super T4,? super T5,? extends R> zipFunction)
zip
does not operate by default on a particular Scheduler
.T1
- the first source Single's value typeT2
- the second source Single's value typeT3
- the third source Single's value typeT4
- the fourth source Single's value typeT5
- the fifth source Single's value typeR
- the result value types1
- the first source Singles2
- a second source Singles3
- a third source Singles4
- a fourth source Singles5
- a fifth source SinglezipFunction
- a function that, when applied to the item emitted by each of the source Singles, results in an
item that will be emitted by the resulting Singlepublic static <T1,T2,T3,T4,T5,T6,R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Single<? extends T4> s4, Single<? extends T5> s5, Single<? extends T6> s6, Func6<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? extends R> zipFunction)
zip
does not operate by default on a particular Scheduler
.T1
- the first source Single's value typeT2
- the second source Single's value typeT3
- the third source Single's value typeT4
- the fourth source Single's value typeT5
- the fifth source Single's value typeT6
- the sixth source Single's value typeR
- the result value types1
- the first source Singles2
- a second source Singles3
- a third source Singles4
- a fourth source Singles5
- a fifth source Singles6
- a sixth source SinglezipFunction
- a function that, when applied to the item emitted by each of the source Singles, results in an
item that will be emitted by the resulting Singlepublic static <T1,T2,T3,T4,T5,T6,T7,R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Single<? extends T4> s4, Single<? extends T5> s5, Single<? extends T6> s6, Single<? extends T7> s7, Func7<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? super T7,? extends R> zipFunction)
zip
does not operate by default on a particular Scheduler
.T1
- the first source Single's value typeT2
- the second source Single's value typeT3
- the third source Single's value typeT4
- the fourth source Single's value typeT5
- the fifth source Single's value typeT6
- the sixth source Single's value typeT7
- the seventh source Single's value typeR
- the result value types1
- the first source Singles2
- a second source Singles3
- a third source Singles4
- a fourth source Singles5
- a fifth source Singles6
- a sixth source Singles7
- a seventh source SinglezipFunction
- a function that, when applied to the item emitted by each of the source Singles, results in an
item that will be emitted by the resulting Singlepublic static <T1,T2,T3,T4,T5,T6,T7,T8,R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Single<? extends T4> s4, Single<? extends T5> s5, Single<? extends T6> s6, Single<? extends T7> s7, Single<? extends T8> s8, Func8<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? super T7,? super T8,? extends R> zipFunction)
zip
does not operate by default on a particular Scheduler
.T1
- the first source Single's value typeT2
- the second source Single's value typeT3
- the third source Single's value typeT4
- the fourth source Single's value typeT5
- the fifth source Single's value typeT6
- the sixth source Single's value typeT7
- the seventh source Single's value typeT8
- the eighth source Single's value typeR
- the result value types1
- the first source Singles2
- a second source Singles3
- a third source Singles4
- a fourth source Singles5
- a fifth source Singles6
- a sixth source Singles7
- a seventh source Singles8
- an eighth source SinglezipFunction
- a function that, when applied to the item emitted by each of the source Singles, results in an
item that will be emitted by the resulting Singlepublic static <T1,T2,T3,T4,T5,T6,T7,T8,T9,R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Single<? extends T4> s4, Single<? extends T5> s5, Single<? extends T6> s6, Single<? extends T7> s7, Single<? extends T8> s8, Single<? extends T9> s9, Func9<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? super T7,? super T8,? super T9,? extends R> zipFunction)
zip
does not operate by default on a particular Scheduler
.T1
- the first source Single's value typeT2
- the second source Single's value typeT3
- the third source Single's value typeT4
- the fourth source Single's value typeT5
- the fifth source Single's value typeT6
- the sixth source Single's value typeT7
- the seventh source Single's value typeT8
- the eighth source Single's value typeT9
- the ninth source Single's value typeR
- the result value types1
- the first source Singles2
- a second source Singles3
- a third source Singles4
- a fourth source Singles5
- a fifth source Singles6
- a sixth source Singles7
- a seventh source Singles8
- an eighth source Singles9
- a ninth source SinglezipFunction
- a function that, when applied to the item emitted by each of the source Singles, results in an
item that will be emitted by the resulting Singlepublic static <R> Single<R> zip(java.lang.Iterable<? extends Single<?>> singles, FuncN<? extends R> zipFunction)
zip
applies this function in strict sequence.
zip
does not operate by default on a particular Scheduler
.R
- the result value typesingles
- an Iterable of source Singles. Should not be empty because Single
either emits result or error.
NoSuchElementException
will be emit as error if Iterable will be empty.zipFunction
- a function that, when applied to an item emitted by each of the source Singles, results in
an item that will be emitted by the resulting Singlepublic final Single<T> cache()
This is useful when you want a Single to cache its response and you can't control the
subscribe/unsubscribe behavior of all the Subscriber
s.
The operator subscribes only when the first downstream subscriber subscribes and maintains
a single subscription towards this Single. In contrast, the operator family of Observable.replay()
that return a ConnectableObservable
require an explicit call to ConnectableObservable.connect()
.
Note: You sacrifice the ability to unsubscribe from the origin when you use the cache
Observer so be careful not to use this Observer on Observables that emit an infinite or very large number
of items that will use up memory.
A possible workaround is to apply `takeUntil` with a predicate or
another source before (and perhaps after) the application of cache().
AtomicBoolean shouldStop = new AtomicBoolean();
source.takeUntil(v -> shouldStop.get())
.cache()
.takeUntil(v -> shouldStop.get())
.subscribe(...);
Since the operator doesn't allow clearing the cached values either, the possible workaround is
to forget all references to it via Observable.onTerminateDetach()
applied along with the previous
workaround:
AtomicBoolean shouldStop = new AtomicBoolean();
source.takeUntil(v -> shouldStop.get())
.onTerminateDetach()
.cache()
.takeUntil(v -> shouldStop.get())
.onTerminateDetach()
.subscribe(...);
cache
does not operate by default on a particular Scheduler
.public final Observable<T> concatWith(Single<? extends T> t1)
concat
does not operate by default on a particular Scheduler
.t1
- a Single to be concatenated after the currentt1
public final <R> Single<R> flatMap(Func1<? super T,? extends Single<? extends R>> func)
flatMap
does not operate by default on a particular Scheduler
.R
- the result value typefunc
- a function that, when applied to the item emitted by the source Single, returns a Singlefunc
when applied to the item emitted by the source Singlepublic final <R> Observable<R> flatMapObservable(Func1<? super T,? extends Observable<? extends R>> func)
flatMapObservable
does not operate by default on a particular Scheduler
.R
- the result value typefunc
- a function that, when applied to the item emitted by the source Single, returns an
Observablefunc
when applied to the item emitted by the source Singlepublic final Completable flatMapCompletable(Func1<? super T,? extends Completable> func)
Completable
that completes based on applying a specified function to the item emitted by the
source Completable
, where that function returns a Completable
.
flatMapCompletable
does not operate by default on a particular Scheduler
.func
- a function that, when applied to the item emitted by the source Single, returns a
Completablefunc
when applied to the item emitted by the source Singlepublic final <R> Single<R> map(Func1<? super T,? extends R> func)
map
does not operate by default on a particular Scheduler
.R
- the result value typefunc
- a function to apply to the item emitted by the Singlepublic final Observable<T> mergeWith(Single<? extends T> t1)
You can combine items emitted by multiple Singles so that they appear as a single Observable, by using
the mergeWith
method.
mergeWith
does not operate by default on a particular Scheduler
.t1
- a Single to be mergedpublic final Single<T> observeOn(Scheduler scheduler)
Scheduler
,
asynchronously.
Scheduler
this operator will usescheduler
- the Scheduler
to notify subscribers onScheduler
subscribeOn(rx.Scheduler)
public final Single<T> onErrorReturn(Func1<java.lang.Throwable,? extends T> resumeFunction)
onError
if it encounters an error.
By default, when a Single encounters an error that prevents it from emitting the expected item to its
subscriber, the Single invokes its subscriber's Observer.onError(java.lang.Throwable)
method, and then quits
without invoking any more of its subscriber's methods. The onErrorReturn
method changes this
behavior. If you pass a function (resumeFunction
) to a Single's onErrorReturn
method, if
the original Single encounters an error, instead of invoking its subscriber's
Observer.onError(java.lang.Throwable)
method, it will instead emit the return value of resumeFunction
.
You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.
onErrorReturn
does not operate by default on a particular Scheduler
.resumeFunction
- a function that returns an item that the new Single will emit if the source Single encounters
an errorpublic final Single<T> onErrorResumeNext(Single<? extends T> resumeSingleInCaseOfError)
Observer.onError(Throwable)
if it encounters an error.
By default, when a Single encounters an error that prevents it from emitting the expected item to
its Observer
, the Single invokes its Observer's onError
method, and then quits
without invoking any more of its Observer's methods. The onErrorResumeNext
method changes this
behavior. If you pass another Single (resumeSingleInCaseOfError
) to a Single's
onErrorResumeNext
method, if the original Single encounters an error, instead of invoking its
Observer's onError
method, it will instead relinquish control to resumeSingleInCaseOfError
which
will invoke the Observer's onNext
method if it is able to do so. In such a case,
because no Single necessarily invokes onError
, the Observer may never know that an error
happened.
You can use this to prevent errors from propagating or to supply fallback data should errors be
encountered.
onErrorResumeNext
does not operate by default on a particular Scheduler
.resumeSingleInCaseOfError
- a Single that will take control if source Single encounters an error.public final Single<T> onErrorResumeNext(Func1<java.lang.Throwable,? extends Single<? extends T>> resumeFunctionInCaseOfError)
Observer.onError(Throwable)
if it encounters an error.
By default, when a Single encounters an error that prevents it from emitting the expected item to
its Observer
, the Single invokes its Observer's onError
method, and then quits
without invoking any more of its Observer's methods. The onErrorResumeNext
method changes this
behavior. If you pass a function that will return another Single (resumeFunctionInCaseOfError
) to a Single's
onErrorResumeNext
method, if the original Single encounters an error, instead of invoking its
Observer's onError
method, it will instead relinquish control to resumeSingleInCaseOfError
which
will invoke the Observer's onNext
method if it is able to do so. In such a case,
because no Single necessarily invokes onError
, the Observer may never know that an error
happened.
You can use this to prevent errors from propagating or to supply fallback data should errors be
encountered.
onErrorResumeNext
does not operate by default on a particular Scheduler
.resumeFunctionInCaseOfError
- a function that returns a Single that will take control if source Single encounters an error.public final Subscription subscribe()
subscribe
does not operate by default on a particular Scheduler
.Subscription
reference can request the Single
stop work.OnErrorNotImplementedException
- if the Single tries to call Observer.onError(java.lang.Throwable)
public final Subscription subscribe(Action1<? super T> onSuccess)
subscribe
does not operate by default on a particular Scheduler
.onSuccess
- the Action1<T>
you have designed to accept the emission from the SingleSubscription
reference can request the Single
stop work.java.lang.IllegalArgumentException
- if onNext
is nullOnErrorNotImplementedException
- if the Single tries to call Observer.onError(java.lang.Throwable)
public final Subscription subscribe(Action1<? super T> onSuccess, Action1<java.lang.Throwable> onError)
subscribe
does not operate by default on a particular Scheduler
.onSuccess
- the Action1<T>
you have designed to accept the emission from the SingleonError
- the Action1<Throwable>
you have designed to accept any error notification from the
SingleSubscription
reference can request the Single
stop work.java.lang.IllegalArgumentException
- if onNext
is null, or
if onError
is nullpublic final Subscription unsafeSubscribe(Subscriber<? super T> subscriber)
Single.OnSubscribe
function without any contract protection,
error handling, unsubscribe, or execution hooks.
Use this only for implementing an Observable.Operator
that requires nested subscriptions. For other
purposes, use subscribe(Subscriber)
which ensures the Rx contract and other functionality.
unsafeSubscribe
does not operate by default on a particular Scheduler
.subscriber
- the Subscriber that will handle the emission or notification from the Singlepublic final Subscription subscribe(Observer<? super T> observer)
observer
- the Observer to subscribepublic final Subscription subscribe(Subscriber<? super T> subscriber)
A typical implementation of subscribe
does the following:
List<T>
object.Subscription
interface. This enables Subscribers to
unsubscribe, that is, to stop receiving the item or notification before the Single completes.
A Single<T>
instance is responsible for accepting all subscriptions and notifying all
Subscribers. Unless the documentation for a particular Single<T>
implementation indicates
otherwise, Subscribers should make no assumptions about the order in which multiple Subscribers will
receive their notifications.
For more information see the ReactiveX documentation.
subscribe
does not operate by default on a particular Scheduler
.subscriber
- the Subscriber
that will handle the emission or notification from the SingleSubscription
reference can request the Single
stop work.java.lang.IllegalStateException
- if subscribe
is unable to obtain an OnSubscribe<>
functionjava.lang.IllegalArgumentException
- if the Subscriber
provided as the argument to subscribe
is null
OnErrorNotImplementedException
- if the Subscriber
's onError
method is nulljava.lang.RuntimeException
- if the Subscriber
's onError
method itself threw a Throwable
public final Subscription subscribe(SingleSubscriber<? super T> te)
SingleSubscriber
that implements functions to handle the
item the Single emits or any error notification it issues.
A typical implementation of subscribe
does the following:
List<T>
object.Subscription
interface. This enables Subscribers to
unsubscribe, that is, to stop receiving the item or notification before the Single completes.
A Single<T>
instance is responsible for accepting all subscriptions and notifying all
Subscribers. Unless the documentation for a particular Single<T>
implementation indicates
otherwise, Subscribers should make no assumptions about the order in which multiple Subscribers will
receive their notifications.
For more information see the ReactiveX documentation.
subscribe
does not operate by default on a particular Scheduler
.te
- the SingleSubscriber
that will handle the emission or notification from the SingleSubscription
reference can request the Single
stop work.java.lang.IllegalStateException
- if subscribe
is unable to obtain an OnSubscribe<>
functionjava.lang.IllegalArgumentException
- if the SingleSubscriber
provided as the argument to subscribe
is null
OnErrorNotImplementedException
- if the SingleSubscriber
's onError
method is nulljava.lang.RuntimeException
- if the SingleSubscriber
's onError
method itself threw a Throwable
public final Single<T> subscribeOn(Scheduler scheduler)
Scheduler
.
Scheduler
this operator will usescheduler
- the Scheduler
to perform subscription actions onScheduler
observeOn(rx.Scheduler)
public final Single<T> takeUntil(Completable other)
other
, this will emit a CancellationException
rather than go to
SingleSubscriber.onSuccess(Object)
.
takeUntil
does not operate by default on a particular Scheduler
.other
- the Completable whose termination will cause takeUntil
to emit the item from the source
Singleother
terminates.public final <E> Single<T> takeUntil(Observable<? extends E> other)
other
, this will emit a CancellationException
rather than go to
SingleSubscriber.onSuccess(Object)
.
takeUntil
does not operate by default on a particular Scheduler
.E
- the type of items emitted by other
other
- the Observable whose first emitted item will cause takeUntil
to emit the item from the source
Singleother
emits
its first itempublic final <E> Single<T> takeUntil(Single<? extends E> other)
other
, this will emit a CancellationException
rather than go to
SingleSubscriber.onSuccess(Object)
.
takeUntil
does not operate by default on a particular Scheduler
.E
- the type of item emitted by other
other
- the Single whose emitted item will cause takeUntil
to emit the item from the source Singleother
emits its itempublic final <R> R to(Func1<? super Single<T>,R> converter)
This allows fluent conversion to any other type.
R
- the resulting object typeconverter
- the function that receives the current Single instance and returns a valuepublic final Observable<T> toObservable()
Observable
.
Observable
that emits a single item T.public final Completable toCompletable()
Completable
that discards result of the Single
(similar to
Observable.ignoreElements()
) and calls onCompleted
when this source Single
calls
onSuccess
. Error terminal event is propagated.
toCompletable
does not operate by default on a particular Scheduler
.Completable
that calls onCompleted
on it's subscriber when the source Single
calls onSuccess
.public final Single<T> timeout(long timeout, java.util.concurrent.TimeUnit timeUnit)
TimeoutException
.
timeout
operates by default on the computation
Scheduler
.timeout
- maximum duration before the Single times outtimeUnit
- the unit of time that applies to the timeout
argument.TimeoutException
in case of a
timeoutpublic final Single<T> timeout(long timeout, java.util.concurrent.TimeUnit timeUnit, Scheduler scheduler)
TimeoutException
.
Scheduler
this operator will usetimeout
- maximum duration before the Single times outtimeUnit
- the unit of time that applies to the timeout
argumentscheduler
- the Scheduler to run the timeout timers onTimeoutException
in case of a
timeoutpublic final Single<T> timeout(long timeout, java.util.concurrent.TimeUnit timeUnit, Single<? extends T> other)
timeout
operates by default on the computation
Scheduler
.timeout
- maximum time before a timeout occurstimeUnit
- the unit of time that applies to the timeout
argumentother
- the fallback Single to use in case of a timeoutpublic final Single<T> timeout(long timeout, java.util.concurrent.TimeUnit timeUnit, Single<? extends T> other, Scheduler scheduler)
Scheduler
this operator will usetimeout
- maximum duration before a timeout occurstimeUnit
- the unit of time that applies to the timeout
argumentother
- the Single to use as the fallback in case of a timeoutscheduler
- the Scheduler
to run the timeout timers onpublic final BlockingSingle<T> toBlocking()
BlockingSingle
(a Single with blocking operators).
toBlocking
does not operate by default on a particular Scheduler
.BlockingSingle
version of this Single.public final <T2,R> Single<R> zipWith(Single<? extends T2> other, Func2<? super T,? super T2,? extends R> zipFunction)
zipWith
does not operate by default on a particular Scheduler
.T2
- the type of items emitted by the other
SingleR
- the type of items emitted by the resulting Singleother
- the other ObservablezipFunction
- a function that combines the pairs of items from the two Observables to generate the items to
be emitted by the resulting Singleother
Observable
and emits the results of zipFunction
applied to these pairspublic final Single<T> doOnError(Action1<java.lang.Throwable> onError)
Single
so that it invokes an action if it calls onError
.
In case the onError action throws, the downstream will receive a composite exception containing the original exception and the exception thrown by onError.
doOnError
does not operate by default on a particular Scheduler
.onError
- the action to invoke if the source Single
calls onError
Single
with the side-effecting behavior appliedpublic final Single<T> doOnEach(Action1<Notification<? extends T>> onNotification)
Single
so that it invokes an action when it calls onSuccess
or onError
.
doOnEach
does not operate by default on a particular Scheduler
.onNotification
- the action to invoke when the source Single
calls onSuccess
or onError
.Single
with the side-effecting behavior appliedpublic final Single<T> doOnSuccess(Action1<? super T> onSuccess)
Single
so that it invokes an action when it calls onSuccess
.
doOnSuccess
does not operate by default on a particular Scheduler
.onSuccess
- the action to invoke when the source Single
calls onSuccess
Single
with the side-effecting behavior appliedpublic final Single<T> doOnSubscribe(Action0 subscribe)
Single
so that it invokes the given action when it is subscribed from
its subscribers. Each subscription will result in an invocation of the given action except when the
source Single
is reference counted, in which case the source Single
will invoke
the given action for the first subscription.
doOnSubscribe
does not operate by default on a particular Scheduler
.subscribe
- the action that gets called when an observer subscribes to this Single
Single
modified so as to call this Action when appropriatepublic final Single<T> delay(long delay, java.util.concurrent.TimeUnit unit, Scheduler scheduler)
Scheduler
this operator will usedelay
- the delay to shift the source byunit
- the time unit of delay
scheduler
- the Scheduler
to use for delayingpublic final Single<T> delay(long delay, java.util.concurrent.TimeUnit unit)
delay
operates by default on the computation
Scheduler
.delay
- the delay to shift the source byunit
- the TimeUnit
in which period
is definedpublic static <T> Single<T> defer(java.util.concurrent.Callable<Single<T>> singleFactory)
Single
that calls a Single
factory to create a Single
for each new Observer
that subscribes. That is, for each subscriber, the actual Single
that subscriber observes is
determined by the factory function.
The defer Observer allows you to defer or delay emitting value from a Single
until such time as an
Observer subscribes to the Single
. This allows an Observer
to easily obtain updates or a
refreshed version of the sequence.
defer
does not operate by default on a particular Scheduler
.T
- the type of the items emitted by the Single
.singleFactory
- the Single
factory function to invoke for each Observer
that subscribes to the
resulting Single
.Single
whose Observer
s' subscriptions trigger an invocation of the given
Single
factory function.public final Single<T> doOnUnsubscribe(Action0 action)
Single
so that it invokes the given action when it is unsubscribed from
its subscribers.
doOnUnsubscribe
does not operate by default on a particular Scheduler
.action
- the action that gets called when this Single
is unsubscribed.Single
modified so as to call this Action when appropriate.public final Single<T> doAfterTerminate(Action0 action)
Action0
to be called when this Single
invokes either
SingleSubscriber.onSuccess(Object)
onSuccess} or onError
.
doAfterTerminate
does not operate by default on a particular Scheduler
.public final Single<T> retry()
onError
(infinite retry count).
If the source Single calls SingleSubscriber.onError(java.lang.Throwable)
, this method will resubscribe to the source
Single rather than propagating the onError
call.
retry
operates by default on the trampoline
Scheduler
.public final Single<T> retry(long count)
onError
up to a specified number of retries.
If the source Single calls SingleSubscriber.onError(java.lang.Throwable)
, this method will resubscribe to the source
Single for a maximum of count
resubscriptions rather than propagating the
onError
call.
retry
operates by default on the trampoline
Scheduler
.count
- number of retry attempts before failingpublic final Single<T> retry(Func2<java.lang.Integer,java.lang.Throwable,java.lang.Boolean> predicate)
onError
and the predicate returns true for that specific exception and retry count.
retry
operates by default on the trampoline
Scheduler
.predicate
- the predicate that determines if a resubscription may happen in case of a specific exception
and retry countretry()
,
ReactiveX operators documentation: Retrypublic final Single<T> retryWhen(Func1<Observable<? extends java.lang.Throwable>,? extends Observable<?>> notificationHandler)
onError
. An onError
notification from the source will result in the emission of a
Throwable
item to the Observable provided as an argument to the notificationHandler
function.
Emissions from the handler Observable
is treated as follows:
Observable
emits an onCompleted
the retryWhen
will call onError
with NoSuchElementException
on the child subscription.Observable
emits an onError
the retryWhen
will call
onError
with the same Throwable instance on the child subscription.
The notificationHandler
function is called for each subscriber individually. This allows per-Subscriber
state to be added to the error notification sequence.
single.retryWhen(error -> {
AtomicInteger counter = new AtomicInteger();
return error.takeWhile(e -> counter.incrementAndGet() < 3).map(e -> "retry");
}).subscribe(...);
Note that you must compose over the input Observable
provided in the function call because retryWhen(rx.functions.Func1<rx.Observable<? extends java.lang.Throwable>, ? extends rx.Observable<?>>)
expects
an emission of the exception to be matched by an event from the handler Observable.
retryWhen
operates by default on the trampoline
Scheduler
.notificationHandler
- receives an Observable of notifications with which a user can complete or error, aborting the
retrypublic static <T,Resource> Single<T> using(Func0<Resource> resourceFactory, Func1<? super Resource,? extends Single<? extends T>> singleFactory, Action1<? super Resource> disposeAction)
using
does not operate by default on a particular Scheduler
.T
- the value type of the generated sourceResource
- the type of the per-subscriber resourceresourceFactory
- the factory function to create a resource object that depends on the SinglesingleFactory
- the factory function to create a SingledisposeAction
- the function that will dispose of the resourcepublic static <T,Resource> Single<T> using(Func0<Resource> resourceFactory, Func1<? super Resource,? extends Single<? extends T>> singleFactory, Action1<? super Resource> disposeAction, boolean disposeEagerly)
disposeEagerly
to true
and unsubscription does not occur
before termination. Otherwise resource disposal will occur on unsubscription. Eager disposal is
particularly appropriate for a synchronous Single that reuses resources. disposeAction
will
only be called once per subscription.
using
does not operate by default on a particular Scheduler
.T
- the value type of the generated sourceResource
- the type of the per-subscriber resourceresourceFactory
- the factory function to create a resource object that depends on the SinglesingleFactory
- the factory function to create a SingledisposeAction
- the function that will dispose of the resourcedisposeEagerly
- if true
then disposal will happen either on unsubscription or just before emission of
a terminal event (onComplete
or onError
).public final Single<T> delaySubscription(Observable<?> other)
onError
of the supplied observer throws,
the exception will be propagated to the downstream subscriber
and will result in skipping the subscription of this Single.
Scheduler
.other
- the Observable that should trigger the subscription
to this Single.@Experimental public final Single<T> unsubscribeOn(Scheduler scheduler)
scheduler
- the target scheduler where to execute the cancellationpublic final AssertableSubscriber<T> test()
Long.MAX_VALUE
and subscribes
it to this Observable.
test
does not operate by default on a particular Scheduler
.History: 1.2.3 - experimental