Class Single<T>
- java.lang.Object
-
- rx.Single<T>
-
- Type Parameters:
T- the type of the item emitted by the Single
- Direct Known Subclasses:
ScalarSynchronousSingle
@Beta public class Single<T> extends java.lang.Object
The Single class implements the Reactive Pattern for a single value response. SeeObservablefor the implementation of the Reactive Pattern for a stream or vector of values.Singlebehaves the same asObservableexcept that it can only emit either a single successful value, or an error (there is no "onComplete" notification as there is forObservable)Like an
Observable, aSingleis 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.
- Since:
- (If this class graduates from "Experimental" replace this parenthetical with the release number)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSingle.OnSubscribe<T>Invoked when Single.execute is called.static interfaceSingle.Transformer<T,R>Transformer function used bycompose(rx.Single.Transformer<? super T, ? extends R>).
-
Field Summary
Fields Modifier and Type Field Description (package private) Observable.OnSubscribe<T>onSubscribe
-
Constructor Summary
Constructors Modifier Constructor Description privateSingle(Observable.OnSubscribe<T> f)protectedSingle(Single.OnSubscribe<T> f)Creates a Single with a Function to execute when it is subscribed to (executed).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static <T> Observable<T>asObservable(Single<T> t)
<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 aSingleSubscriberexecutes it or aSubscribersubscribes 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 an 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 an 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 anAction0to be called when thisSingleinvokes eitherSingleSubscriber.onSuccess(Object)onSuccess} oronError.Single<T>doOnError(Action1<java.lang.Throwable> onError)Modifies the sourceSingleso that it invokes an action if it callsonError.Single<T>doOnSubscribe(Action0 subscribe)Modifies the sourceSingleso that it invokes the given action when it is subscribed from its subscribers.Single<T>doOnSuccess(Action1<? super T> onSuccess)Modifies the sourceSingleso that it invokes an action when it callsonSuccess.Single<T>doOnUnsubscribe(Action0 action)Modifies the sourceSingleso 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'sonErrormethod 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.<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 aFutureinto aSingle.static <T> Single<T>from(java.util.concurrent.Future<? extends T> future, long timeout, java.util.concurrent.TimeUnit unit)Converts aFutureinto aSingle, 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 aSinglethat invokes passed function and emits its result for each new Observer that subscribes.(package private) static <T> Single<? extends T>[]iterableToArray(java.lang.Iterable<? extends Single<? extends T>> singlesIterable)FOR INTERNAL USE ONLY.static <T> Single<T>just(T value)Returns aSinglethat 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> Single<T>merge(Single<? extends Single<? extends T>> source)Flattens aSinglethat emits aSingleinto a singleSinglethat emits the item emitted by the nestedSingle, 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.Observable<T>mergeWith(Single<? extends T> t1)Flattens this and another Single into a single Observable, without any transformation.private Single<Observable<T>>nest()INTERNAL: Used with lift and operators.Single<T>observeOn(Scheduler scheduler)Modifies a Single to emit its item (or notify of its error) on a specifiedScheduler, asynchronously.Single<T>onErrorResumeNext(Func1<java.lang.Throwable,? extends Single<? extends T>> resumeFunctionInCaseOfError)Instructs a Single to pass control to another Single rather than invokingObserver.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 invokingObserver.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 invokingonErrorif it encounters an error.Single<T>retry()Returns a Single that mirrors the source Single, resubscribing to it if it callsonError(infinite retry count).Single<T>retry(long count)Returns an Single that mirrors the source Single, resubscribing to it if it callsonErrorup to a specified number of retries.Single<T>retry(Func2<java.lang.Integer,java.lang.Throwable,java.lang.Boolean> predicate)Returns an Single that mirrors the source Single, resubscribing to it if it callsonErrorand the predicate returns true for that specific exception and retry count.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 anonError.Subscriptionsubscribe()Subscribes to a Single but ignore its emission or notification.Subscriptionsubscribe(Action1<? super T> onSuccess)Subscribes to a Single and provides a callback to handle the item it emits.Subscriptionsubscribe(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.Subscriptionsubscribe(Observer<? super T> observer)Subscribes an Observer to this single and returns a Subscription that allows unsubscription.Subscriptionsubscribe(SingleSubscriber<? super T> te)Subscribes to a Single and provides aSingleSubscriberthat implements functions to handle the item the Single emits or any error notification it issues.Subscriptionsubscribe(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 specifiedScheduler.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.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.BlockingSingle<T>toBlocking()Converts a Single into aBlockingSingle(a Single with blocking operators).CompletabletoCompletable()Returns aCompletablethat discards result of theSingle(similar toObservable.ignoreElements()) and callsonCompletedwhen this sourceSinglecallsonSuccess.Observable<T>toObservable()Converts this Single into anObservable.SubscriptionunsafeSubscribe(Subscriber<? super T> subscriber)Subscribes to a Single and invokes theSingle.OnSubscribefunction without any contract protection, error handling, unsubscribe, or execution hooks.static <T,Resource>
Single<T>using(Func0<Resource> resourceFactory, Func1<? super Resource,? extends Single<? extends T>> singleFactory, Action1<? super Resource> disposeAction)Constructs an Single that creates a dependent resource object which is disposed of on unsubscription.static <T,Resource>
Single<T>using(Func0<Resource> resourceFactory, Func1<? super Resource,? extends Single<? extends T>> singleFactory, Action1<? super Resource> disposeAction, boolean disposeEagerly)Constructs an Single that creates a dependent resource object which is disposed of just before termination if you have setdisposeEagerlytotrueand 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>
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)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>
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)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>
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)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>
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)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>
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)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>
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)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>
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)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.
-
-
-
Field Detail
-
onSubscribe
final Observable.OnSubscribe<T> onSubscribe
-
-
Constructor Detail
-
Single
protected Single(Single.OnSubscribe<T> f)
Creates a Single with a Function to execute when it is subscribed to (executed).Note: Use
create(OnSubscribe)to create a Single, instead of this constructor, unless you specifically have a need for inheritance.- Parameters:
f-OnExecuteto be executed whenexecute(SingleSubscriber)orsubscribe(Subscriber)is called
-
Single
private Single(Observable.OnSubscribe<T> f)
-
-
Method Detail
-
create
public static <T> Single<T> create(Single.OnSubscribe<T> f)
Returns a Single that will execute the specified function when aSingleSubscriberexecutes it or aSubscribersubscribes to it.
Write the function you pass to
createso that it behaves as a Single: It should invoke the SingleSubscriberonSuccessand/oronErrormethods appropriately.A well-formed Single must invoke either the SingleSubscriber's
onSuccessmethod exactly once or itsonErrormethod exactly once.- Scheduler:
createdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of the item that this Single emits- Parameters:
f- a function that accepts anSingleSubscriber<T>, and invokes itsonSuccessoronErrormethods as appropriate- Returns:
- a Single that, when a
Subscribersubscribes to it, will execute the specified function - See Also:
- ReactiveX operators documentation: Create
-
lift
@Experimental public final <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.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) usecompose(rx.Single.Transformer<? super T, ? extends R>).- Scheduler:
liftdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the downstream's value type (output)- Parameters:
lift- the Operator that implements the Single-operating function to be applied to the source Single- Returns:
- a Single that is the result of applying the lifted Operator to the source Single
- See Also:
- RxJava wiki: Implementing Your Own Operators
-
compose
public <R> Single<R> compose(Single.Transformer<? super T,? extends R> transformer)
Transform a Single by applying a particular Transformer function to it.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) usecompose.- Scheduler:
composedoes not operate by default on a particularScheduler.
- Type Parameters:
R- the value type of the single returned by the transformer function- Parameters:
transformer- implements the function that transforms the source Single- Returns:
- the source Single, transformed by the transformer function
- See Also:
- RxJava wiki: Implementing Your Own Operators
-
asObservable
private static <T> Observable<T> asObservable(Single<T> t)

-
nest
private Single<Observable<T>> nest()
INTERNAL: Used with lift and operators. Converts the sourceSingle<T>into anSingle<Observable<T>>that emits an Observable that emits the same emission as the source Single.
- Scheduler:
nestdoes not operate by default on a particularScheduler.
- Returns:
- a Single that emits an Observable that emits the same item as the source Single
- See Also:
- ReactiveX operators documentation: To
-
concat
public 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.
- Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
t1- an Single to be concatenatedt2- an Single to be concatenated- Returns:
- an Observable that emits items emitted by the two source Singles, one after the other.
- See Also:
- ReactiveX operators documentation: Concat
-
concat
public 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.
- Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
t1- a Single to be concatenatedt2- a Single to be concatenatedt3- a Single to be concatenated- Returns:
- an Observable that emits items emitted by the three source Singles, one after the other.
- See Also:
- ReactiveX operators documentation: Concat
-
concat
public 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.
- Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
t1- a Single to be concatenatedt2- a Single to be concatenatedt3- a Single to be concatenatedt4- a Single to be concatenated- Returns:
- an Observable that emits items emitted by the four source Singles, one after the other.
- See Also:
- ReactiveX operators documentation: Concat
-
concat
public 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.
- Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
t1- a Single to be concatenatedt2- a Single to be concatenatedt3- a Single to be concatenatedt4- a Single to be concatenatedt5- a Single to be concatenated- Returns:
- an Observable that emits items emitted by the five source Singles, one after the other.
- See Also:
- ReactiveX operators documentation: Concat
-
concat
public 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.
- Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
t1- 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 concatenated- Returns:
- an Observable that emits items emitted by the six source Singles, one after the other.
- See Also:
- ReactiveX operators documentation: Concat
-
concat
public 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.
- Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
t1- 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 concatenated- Returns:
- an Observable that emits items emitted by the seven source Singles, one after the other.
- See Also:
- ReactiveX operators documentation: Concat
-
concat
public 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.
- Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
t1- 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 concatenated- Returns:
- an Observable that emits items emitted by the eight source Singles, one after the other.
- See Also:
- ReactiveX operators documentation: Concat
-
concat
public 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.
- Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
t1- 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 concatenated- Returns:
- an Observable that emits items emitted by the nine source Singles, one after the other.
- See Also:
- ReactiveX operators documentation: Concat
-
error
public static <T> Single<T> error(java.lang.Throwable exception)
Returns a Single that invokes a subscriber'sonErrormethod when the subscriber subscribes to it.
- Scheduler:
errordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of the item (ostensibly) emitted by the Single- Parameters:
exception- the particular Throwable to pass toonError- Returns:
- a Single that invokes the subscriber's
onErrormethod when the subscriber subscribes to it - See Also:
- ReactiveX operators documentation: Throw
-
from
public static <T> Single<T> from(java.util.concurrent.Future<? extends T> future)
Converts aFutureinto aSingle.
You can convert any object that supports the
Futureinterface into a Single that emits the return value of theFuture.get()method of that object, by passing the object into thefrommethod.Important note: This Single is blocking; you cannot unsubscribe from it.
- Scheduler:
fromdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of object that theFuturereturns, and also the type of item to be emitted by the resultingSingle- Parameters:
future- the sourceFuture- Returns:
- a
Singlethat emits the item from the sourceFuture - See Also:
- ReactiveX operators documentation: From
-
from
public static <T> Single<T> from(java.util.concurrent.Future<? extends T> future, long timeout, java.util.concurrent.TimeUnit unit)
Converts aFutureinto aSingle, with a timeout on the Future.
You can convert any object that supports the
Futureinterface into aSinglethat emits the return value of theFuture.get()method of that object, by passing the object into thefrommethod.Important note: This
Singleis blocking; you cannot unsubscribe from it.- Scheduler:
fromdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of object that theFuturereturns, and also the type of item to be emitted by the resultingSingle- Parameters:
future- the sourceFuturetimeout- the maximum time to wait before callinggetunit- theTimeUnitof thetimeoutargument- Returns:
- a
Singlethat emits the item from the sourceFuture - See Also:
- ReactiveX operators documentation: From
-
from
public static <T> Single<T> from(java.util.concurrent.Future<? extends T> future, Scheduler scheduler)
Converts aFuture, operating on a specifiedScheduler, into aSingle.
You can convert any object that supports the
Futureinterface into aSinglethat emits the return value of theFuture.get()method of that object, by passing the object into thefrommethod.- Scheduler:
- you specify which
Schedulerthis operator will use
- Type Parameters:
T- the type of object that theFuturereturns, and also the type of item to be emitted by the resultingSingle- Parameters:
future- the sourceFuturescheduler- theSchedulerto wait for the Future on. Use a Scheduler such asSchedulers.io()that can block and wait on the Future- Returns:
- a
Singlethat emits the item from the sourceFuture - See Also:
- ReactiveX operators documentation: From
-
fromCallable
@Beta public static <T> Single<T> fromCallable(java.util.concurrent.Callable<? extends T> func)
Returns aSinglethat 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 theSingle.- Scheduler:
fromCallabledoes not operate by default on a particularScheduler.
-
just
public static <T> Single<T> just(T value)
Returns aSinglethat emits a specified item.
To convert any object into a
Singlethat emits that object, pass that object into thejustmethod.- Scheduler:
justdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of that item- Parameters:
value- the item to emit- Returns:
- a
Singlethat emitsvalue - See Also:
- ReactiveX operators documentation: Just
-
merge
public static <T> Single<T> merge(Single<? extends Single<? extends T>> source)
Flattens aSinglethat emits aSingleinto a singleSinglethat emits the item emitted by the nestedSingle, without any transformation.
- Scheduler:
mergedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type of the sources and the output- Parameters:
source- aSinglethat emits aSingle- Returns:
- a
Singlethat emits the item that is the result of flattening theSingleemitted bysource - See Also:
- ReactiveX operators documentation: Merge
-
merge
public static <T> Observable<T> merge(Single<? extends T> t1, Single<? extends T> t2)
Flattens two Singles into a single Observable, without any transformation.
You can combine items emitted by multiple Singles so that they appear as a single Observable, by using the
mergemethod.- Scheduler:
mergedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
t1- a Single to be mergedt2- a Single to be merged- Returns:
- an Observable that emits all of the items emitted by the source Singles
- See Also:
- ReactiveX operators documentation: Merge
-
merge
public 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.
You can combine items emitted by multiple Singles so that they appear as a single Observable, by using the
mergemethod.- Scheduler:
mergedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
t1- a Single to be mergedt2- a Single to be mergedt3- a Single to be merged- Returns:
- an Observable that emits all of the items emitted by the source Singles
- See Also:
- ReactiveX operators documentation: Merge
-
merge
public 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.
You can combine items emitted by multiple Singles so that they appear as a single Observable, by using the
mergemethod.- Scheduler:
mergedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
t1- a Single to be mergedt2- a Single to be mergedt3- a Single to be mergedt4- a Single to be merged- Returns:
- an Observable that emits all of the items emitted by the source Singles
- See Also:
- ReactiveX operators documentation: Merge
-
merge
public 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.
You can combine items emitted by multiple Singles so that they appear as a single Observable, by using the
mergemethod.- Scheduler:
mergedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
t1- a Single to be mergedt2- a Single to be mergedt3- a Single to be mergedt4- a Single to be mergedt5- a Single to be merged- Returns:
- an Observable that emits all of the items emitted by the source Singles
- See Also:
- ReactiveX operators documentation: Merge
-
merge
public 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.
You can combine items emitted by multiple Singles so that they appear as a single Observable, by using the
mergemethod.- Scheduler:
mergedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
t1- 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 merged- Returns:
- an Observable that emits all of the items emitted by the source Singles
- See Also:
- ReactiveX operators documentation: Merge
-
merge
public 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.
You can combine items emitted by multiple Singles so that they appear as a single Observable, by using the
mergemethod.- Scheduler:
mergedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
t1- 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 merged- Returns:
- an Observable that emits all of the items emitted by the source Singles
- See Also:
- ReactiveX operators documentation: Merge
-
merge
public 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.
You can combine items emitted by multiple Singles so that they appear as a single Observable, by using the
mergemethod.- Scheduler:
mergedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
t1- 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 merged- Returns:
- an Observable that emits all of the items emitted by the source Singles
- See Also:
- ReactiveX operators documentation: Merge
-
merge
public 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.
You can combine items emitted by multiple Singles so that they appear as a single Observable, by using the
mergemethod.- Scheduler:
mergedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
t1- 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 merged- Returns:
- an Observable that emits all of the items emitted by the source Singles
- See Also:
- ReactiveX operators documentation: Merge
-
zip
public 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.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the first source Single's value typeT2- the second source Single's value typeR- the result value type- Parameters:
s1- 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 Single- Returns:
- a Single that emits the zipped results
- See Also:
- ReactiveX operators documentation: Zip
-
zip
public 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)
Returns a Single that emits the results of a specified combiner function applied to three items emitted by three other Singles.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
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 type- Parameters:
s1- 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 Single- Returns:
- a Single that emits the zipped results
- See Also:
- ReactiveX operators documentation: Zip
-
zip
public 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)
Returns an Observable that emits the results of a specified combiner function applied to four items emitted by four other Singles.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
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 type- Parameters:
s1- 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 Single- Returns:
- a Single that emits the zipped results
- See Also:
- ReactiveX operators documentation: Zip
-
zip
public 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)
Returns an Observable that emits the results of a specified combiner function applied to five items emitted by five other Singles.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
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 type- Parameters:
s1- 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 Single- Returns:
- a Single that emits the zipped results
- See Also:
- ReactiveX operators documentation: Zip
-
zip
public 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)
Returns an Observable that emits the results of a specified combiner function applied to six items emitted by six other Singles.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
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 type- Parameters:
s1- 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 Single- Returns:
- a Single that emits the zipped results
- See Also:
- ReactiveX operators documentation: Zip
-
zip
public 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)
Returns an Observable that emits the results of a specified combiner function applied to seven items emitted by seven other Singles.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
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 type- Parameters:
s1- 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 Single- Returns:
- a Single that emits the zipped results
- See Also:
- ReactiveX operators documentation: Zip
-
zip
public 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)
Returns an Observable that emits the results of a specified combiner function applied to eight items emitted by eight other Singles.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
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 eigth source Single's value typeR- the result value type- Parameters:
s1- 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 Single- Returns:
- a Single that emits the zipped results
- See Also:
- ReactiveX operators documentation: Zip
-
zip
public 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)
Returns an Observable that emits the results of a specified combiner function applied to nine items emitted by nine other Singles.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
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 eigth source Single's value typeT9- the ninth source Single's value typeR- the result value type- Parameters:
s1- 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 Single- Returns:
- a Single that emits the zipped results
- See Also:
- ReactiveX operators documentation: Zip
-
zip
public 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.zipapplies this function in strict sequence.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result value type- Parameters:
singles- an Iterable of source Singles. Should not be empty becauseSingleeither emits result or error.NoSuchElementExceptionwill 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 Single- Returns:
- a Single that emits the zipped results
- See Also:
- ReactiveX operators documentation: Zip
-
concatWith
public final 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.
- Scheduler:
concatdoes not operate by default on a particularScheduler.
- Parameters:
t1- a Single to be concatenated after the current- Returns:
- an Observable that emits the item emitted by the source Single, followed by the item emitted by
t1 - See Also:
- ReactiveX operators documentation: Concat
-
flatMap
public final <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.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result value type- Parameters:
func- a function that, when applied to the item emitted by the source Single, returns a Single- Returns:
- the Single returned from
funcwhen applied to the item emitted by the source Single - See Also:
- ReactiveX operators documentation: FlatMap
-
flatMapObservable
public final <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.
- Scheduler:
flatMapObservabledoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result value type- Parameters:
func- a function that, when applied to the item emitted by the source Single, returns an Observable- Returns:
- the Observable returned from
funcwhen applied to the item emitted by the source Single - See Also:
- ReactiveX operators documentation: FlatMap
-
map
public final <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.
- Scheduler:
mapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result value type- Parameters:
func- a function to apply to the item emitted by the Single- Returns:
- a Single that emits the item from the source Single, transformed by the specified function
- See Also:
- ReactiveX operators documentation: Map
-
mergeWith
public final Observable<T> mergeWith(Single<? extends T> t1)
Flattens this and another Single into a single Observable, without any transformation.
You can combine items emitted by multiple Singles so that they appear as a single Observable, by using the
mergeWithmethod.- Scheduler:
mergeWithdoes not operate by default on a particularScheduler.
- Parameters:
t1- a Single to be merged- Returns:
- an Observable that emits all of the items emitted by the source Singles
- See Also:
- ReactiveX operators documentation: Merge
-
observeOn
public final Single<T> observeOn(Scheduler scheduler)
Modifies a Single to emit its item (or notify of its error) on a specifiedScheduler, asynchronously.
- Scheduler:
- you specify which
Schedulerthis operator will use
- Parameters:
scheduler- theSchedulerto notify subscribers on- Returns:
- the source Single modified so that its subscribers are notified on the specified
Scheduler - See Also:
- ReactiveX operators documentation: ObserveOn,
RxJava Threading Examples,
subscribeOn(rx.Scheduler)
-
onErrorReturn
public final Single<T> onErrorReturn(Func1<java.lang.Throwable,? extends T> resumeFunction)
Instructs a Single to emit an item (returned by a specified function) rather than invokingonErrorif 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. TheonErrorReturnmethod changes this behavior. If you pass a function (resumeFunction) to a Single'sonErrorReturnmethod, if the original Single encounters an error, instead of invoking its subscriber'sObserver.onError(java.lang.Throwable)method, it will instead emit the return value ofresumeFunction.You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.
- Scheduler:
onErrorReturndoes not operate by default on a particularScheduler.
- Parameters:
resumeFunction- a function that returns an item that the new Single will emit if the source Single encounters an error- Returns:
- the original Single with appropriately modified behavior
- See Also:
- ReactiveX operators documentation: Catch
-
onErrorResumeNext
@Experimental public final Single<T> onErrorResumeNext(Single<? extends T> resumeSingleInCaseOfError)
Instructs a Single to pass control to another Single rather than invokingObserver.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'sonErrormethod, and then quits without invoking any more of its Observer's methods. TheonErrorResumeNextmethod changes this behavior. If you pass another Single (resumeSingleInCaseOfError) to an Single'sonErrorResumeNextmethod, if the original Single encounters an error, instead of invoking its Observer'sonErrormethod, it will instead relinquish control toresumeSingleInCaseOfErrorwhich will invoke the Observer'sonNextmethod if it is able to do so. In such a case, because no Single necessarily invokesonError, 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.- Scheduler:
onErrorResumeNextdoes not operate by default on a particularScheduler.
- Parameters:
resumeSingleInCaseOfError- a Single that will take control if source Single encounters an error.- Returns:
- the original Single, with appropriately modified behavior.
- Since:
- (if this graduates from Experimental/Beta to supported, replace this parenthetical with the release number)
- See Also:
- ReactiveX operators documentation: Catch
-
onErrorResumeNext
@Experimental public final Single<T> onErrorResumeNext(Func1<java.lang.Throwable,? extends Single<? extends T>> resumeFunctionInCaseOfError)
Instructs a Single to pass control to another Single rather than invokingObserver.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'sonErrormethod, and then quits without invoking any more of its Observer's methods. TheonErrorResumeNextmethod changes this behavior. If you pass a function that will return another Single (resumeFunctionInCaseOfError) to an Single'sonErrorResumeNextmethod, if the original Single encounters an error, instead of invoking its Observer'sonErrormethod, it will instead relinquish control toresumeSingleInCaseOfErrorwhich will invoke the Observer'sonNextmethod if it is able to do so. In such a case, because no Single necessarily invokesonError, 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.- Scheduler:
onErrorResumeNextdoes not operate by default on a particularScheduler.
- Parameters:
resumeFunctionInCaseOfError- a function that returns a Single that will take control if source Single encounters an error.- Returns:
- the original Single, with appropriately modified behavior.
- Since:
- (if this graduates from Experimental/Beta to supported, replace this parenthetical with the release number)
- See Also:
- ReactiveX operators documentation: Catch
-
subscribe
public final Subscription subscribe()
Subscribes to a Single but ignore its emission or notification.- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Returns:
- a
Subscriptionreference can request theSinglestop work. - Throws:
OnErrorNotImplementedException- if the Single tries to callObserver.onError(java.lang.Throwable)- See Also:
- ReactiveX operators documentation: Subscribe
-
subscribe
public final Subscription subscribe(Action1<? super T> onSuccess)
Subscribes to a Single and provides a callback to handle the item it emits.- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Parameters:
onSuccess- theAction1<T>you have designed to accept the emission from the Single- Returns:
- a
Subscriptionreference can request theSinglestop work. - Throws:
java.lang.IllegalArgumentException- ifonNextis nullOnErrorNotImplementedException- if the Single tries to callObserver.onError(java.lang.Throwable)- See Also:
- ReactiveX operators documentation: Subscribe
-
subscribe
public final 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.- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Parameters:
onSuccess- theAction1<T>you have designed to accept the emission from the SingleonError- theAction1<Throwable>you have designed to accept any error notification from the Single- Returns:
- a
Subscriptionreference can request theSinglestop work. - Throws:
java.lang.IllegalArgumentException- ifonNextis null, or ifonErroris null- See Also:
- ReactiveX operators documentation: Subscribe
-
unsafeSubscribe
public final Subscription unsafeSubscribe(Subscriber<? super T> subscriber)
Subscribes to a Single and invokes theSingle.OnSubscribefunction without any contract protection, error handling, unsubscribe, or execution hooks.Use this only for implementing an
Observable.Operatorthat requires nested subscriptions. For other purposes, usesubscribe(Subscriber)which ensures the Rx contract and other functionality.- Scheduler:
unsafeSubscribedoes not operate by default on a particularScheduler.
- Parameters:
subscriber- the Subscriber that will handle the emission or notification from the Single- Returns:
- the subscription that allows unsubscribing
-
subscribe
public final Subscription subscribe(Observer<? super T> observer)
Subscribes an Observer to this single and returns a Subscription that allows unsubscription.- Parameters:
observer- the Observer to subscribe- Returns:
- the Subscription that allows unsubscription
-
subscribe
public final 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.A typical implementation of
subscribedoes the following:- It stores a reference to the Subscriber in a collection object, such as a
List<T>object. - It returns a reference to the
Subscriptioninterface. 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 particularSingle<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.
- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Parameters:
subscriber- theSubscriberthat will handle the emission or notification from the Single- Returns:
- a
Subscriptionreference can request theSinglestop work. - Throws:
java.lang.IllegalStateException- ifsubscribeis unable to obtain anOnSubscribe<>functionjava.lang.IllegalArgumentException- if theSubscriberprovided as the argument tosubscribeisnullOnErrorNotImplementedException- if theSubscriber'sonErrormethod is nulljava.lang.RuntimeException- if theSubscriber'sonErrormethod itself threw aThrowable- See Also:
- ReactiveX operators documentation: Subscribe
- It stores a reference to the Subscriber in a collection object, such as a
-
subscribe
public final Subscription subscribe(SingleSubscriber<? super T> te)
Subscribes to a Single and provides aSingleSubscriberthat implements functions to handle the item the Single emits or any error notification it issues.A typical implementation of
subscribedoes the following:- It stores a reference to the Subscriber in a collection object, such as a
List<T>object. - It returns a reference to the
Subscriptioninterface. 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 particularSingle<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.
- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Parameters:
te- theSingleSubscriberthat will handle the emission or notification from the Single- Returns:
- a
Subscriptionreference can request theSinglestop work. - Throws:
java.lang.IllegalStateException- ifsubscribeis unable to obtain anOnSubscribe<>functionjava.lang.IllegalArgumentException- if theSingleSubscriberprovided as the argument tosubscribeisnullOnErrorNotImplementedException- if theSingleSubscriber'sonErrormethod is nulljava.lang.RuntimeException- if theSingleSubscriber'sonErrormethod itself threw aThrowable- See Also:
- ReactiveX operators documentation: Subscribe
- It stores a reference to the Subscriber in a collection object, such as a
-
subscribeOn
public final Single<T> subscribeOn(Scheduler scheduler)
Asynchronously subscribes subscribers to this Single on the specifiedScheduler.
- Scheduler:
- you specify which
Schedulerthis operator will use
- Parameters:
scheduler- theSchedulerto perform subscription actions on- Returns:
- the source Single modified so that its subscriptions happen on the specified
Scheduler - See Also:
- ReactiveX operators documentation: SubscribeOn,
RxJava Threading Examples,
observeOn(rx.Scheduler)
-
takeUntil
public final Single<T> takeUntil(Completable other)
Returns a Single that emits the item emitted by the source Single until a Completable terminates. Upon termination ofother, this will emit aCancellationExceptionrather than go toSingleSubscriber.onSuccess(Object).
- Scheduler:
takeUntildoes not operate by default on a particularScheduler.
- Parameters:
other- the Completable whose termination will causetakeUntilto emit the item from the source Single- Returns:
- a Single that emits the item emitted by the source Single until such time as
otherterminates. - See Also:
- ReactiveX operators documentation: TakeUntil
-
takeUntil
public final <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. Upon emission of an item fromother, this will emit aCancellationExceptionrather than go toSingleSubscriber.onSuccess(Object).
- Scheduler:
takeUntildoes not operate by default on a particularScheduler.
- Type Parameters:
E- the type of items emitted byother- Parameters:
other- the Observable whose first emitted item will causetakeUntilto emit the item from the source Single- Returns:
- a Single that emits the item emitted by the source Single until such time as
otheremits its first item - See Also:
- ReactiveX operators documentation: TakeUntil
-
takeUntil
public final <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. Upon emission of an item fromother, this will emit aCancellationExceptionrather than go toSingleSubscriber.onSuccess(Object).
- Scheduler:
takeUntildoes not operate by default on a particularScheduler.
- Type Parameters:
E- the type of item emitted byother- Parameters:
other- the Single whose emitted item will causetakeUntilto emit the item from the source Single- Returns:
- a Single that emits the item emitted by the source Single until such time as
otheremits its item - See Also:
- ReactiveX operators documentation: TakeUntil
-
toObservable
public final Observable<T> toObservable()
Converts this Single into anObservable.
- Returns:
- an
Observablethat emits a single item T.
-
toCompletable
@Experimental public final Completable toCompletable()
Returns aCompletablethat discards result of theSingle(similar toObservable.ignoreElements()) and callsonCompletedwhen this sourceSinglecallsonSuccess. Error terminal event is propagated.
- Scheduler:
toCompletabledoes not operate by default on a particularScheduler.
- Returns:
- a
Completablethat callsonCompletedon it's subscriber when the sourceSinglecallsonSuccess. - Since:
- (if this graduates from Experimental/Beta to supported, replace this parenthetical with the release number).
- See Also:
- ReactiveX documentation: Completable
-
timeout
public final 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. If it is not emitted within the specified timeout duration, the resulting Single terminates and notifies subscribers of aTimeoutException.
- Scheduler:
- This version of
timeoutoperates by default on thecomputationScheduler.
- Parameters:
timeout- maximum duration before the Single times outtimeUnit- the unit of time that applies to thetimeoutargument.- Returns:
- the source Single modified to notify subscribers of a
TimeoutExceptionin case of a timeout - See Also:
- ReactiveX operators documentation: Timeout
-
timeout
public final 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. If the item is not emitted within the specified timeout duration, the resulting Single terminates and notifies subscribers of aTimeoutException.
- Scheduler:
- you specify which
Schedulerthis operator will use
- Parameters:
timeout- maximum duration before the Single times outtimeUnit- the unit of time that applies to thetimeoutargumentscheduler- the Scheduler to run the timeout timers on- Returns:
- the source Single modified to notify subscribers of a
TimeoutExceptionin case of a timeout - See Also:
- ReactiveX operators documentation: Timeout
-
timeout
public final 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. If it is not emitted within the specified timeout duration, the resulting Single instead mirrors a fallback Single.
- Scheduler:
- This version of
timeoutoperates by default on thecomputationScheduler.
- Parameters:
timeout- maximum time before a timeout occurstimeUnit- the unit of time that applies to thetimeoutargumentother- the fallback Single to use in case of a timeout- Returns:
- the source Single modified to switch to the fallback Single in case of a timeout
- See Also:
- ReactiveX operators documentation: Timeout
-
timeout
public final 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. If the item isn't emitted within the specified timeout duration, the resulting Single instead mirrors a fallback Single.
- Scheduler:
- you specify which
Schedulerthis operator will use
- Parameters:
timeout- maximum duration before a timeout occurstimeUnit- the unit of time that applies to thetimeoutargumentother- the Single to use as the fallback in case of a timeoutscheduler- theSchedulerto run the timeout timers on- Returns:
- the source Single modified so that it will switch to the fallback Single in case of a timeout
- See Also:
- ReactiveX operators documentation: Timeout
-
toBlocking
@Experimental public final BlockingSingle<T> toBlocking()
Converts a Single into aBlockingSingle(a Single with blocking operators).- Scheduler:
toBlockingdoes not operate by default on a particularScheduler.
- Returns:
- a
BlockingSingleversion of this Single. - See Also:
- ReactiveX operators documentation: To
-
zipWith
public final <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.
- Scheduler:
zipWithdoes not operate by default on a particularScheduler.
- Type Parameters:
T2- the type of items emitted by theotherSingleR- the type of items emitted by the resulting Single- Parameters:
other- 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 Single- Returns:
- an Observable that pairs up values from the source Observable and the
otherObservable and emits the results ofzipFunctionapplied to these pairs - See Also:
- ReactiveX operators documentation: Zip
-
doOnError
@Experimental public final Single<T> doOnError(Action1<java.lang.Throwable> onError)
Modifies the sourceSingleso that it invokes an action if it callsonError.In case the onError action throws, the downstream will receive a composite exception containing the original exception and the exception thrown by onError.
- Scheduler:
doOnErrordoes not operate by default on a particularScheduler.
- Parameters:
onError- the action to invoke if the sourceSinglecallsonError- Returns:
- the source
Singlewith the side-effecting behavior applied - See Also:
- ReactiveX operators documentation: Do
-
doOnSuccess
@Experimental public final Single<T> doOnSuccess(Action1<? super T> onSuccess)
Modifies the sourceSingleso that it invokes an action when it callsonSuccess.
- Scheduler:
doOnSuccessdoes not operate by default on a particularScheduler.
- Parameters:
onSuccess- the action to invoke when the sourceSinglecallsonSuccess- Returns:
- the source
Singlewith the side-effecting behavior applied - See Also:
- ReactiveX operators documentation: Do
-
doOnSubscribe
@Experimental public final Single<T> doOnSubscribe(Action0 subscribe)
Modifies the sourceSingleso 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 sourceSingleis reference counted, in which case the sourceSinglewill invoke the given action for the first subscription.
- Scheduler:
doOnSubscribedoes not operate by default on a particularScheduler.
- Parameters:
subscribe- the action that gets called when an observer subscribes to thisSingle- Returns:
- the source
Singlemodified so as to call this Action when appropriate - See Also:
- ReactiveX operators documentation: Do
-
delay
@Experimental public final Single<T> delay(long delay, java.util.concurrent.TimeUnit unit, Scheduler scheduler)
Returns an Single that emits the items emitted by the source Single shifted forward in time by a specified delay. Error notifications from the source Single are not delayed.
- Scheduler:
- you specify which
Schedulerthis operator will use
- Parameters:
delay- the delay to shift the source byunit- the time unit ofdelayscheduler- theSchedulerto use for delaying- Returns:
- the source Single shifted in time by the specified delay
- See Also:
- ReactiveX operators documentation: Delay
-
delay
@Experimental public final Single<T> delay(long delay, java.util.concurrent.TimeUnit unit)
Returns an Single that emits the items emitted by the source Single shifted forward in time by a specified delay. Error notifications from the source Observable are not delayed.
- Scheduler:
- This version of
delayoperates by default on thecomputationScheduler.
- Parameters:
delay- the delay to shift the source byunit- theTimeUnitin whichperiodis defined- Returns:
- the source Single shifted in time by the specified delay
- See Also:
- ReactiveX operators documentation: Delay
-
defer
@Experimental public static <T> Single<T> defer(java.util.concurrent.Callable<Single<T>> singleFactory)
Returns aSinglethat calls aSinglefactory to create aSinglefor each new Observer that subscribes. That is, for each subscriber, the actualSinglethat subscriber observes is determined by the factory function.
The defer Observer allows you to defer or delay emitting value from a
Singleuntil such time as an Observer subscribes to theSingle. This allows anObserverto easily obtain updates or a refreshed version of the sequence.- Scheduler:
deferdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of the items emitted by theSingle.- Parameters:
singleFactory- theSinglefactory function to invoke for eachObserverthat subscribes to the resultingSingle.- Returns:
- a
SinglewhoseObservers' subscriptions trigger an invocation of the givenSinglefactory function. - See Also:
- ReactiveX operators documentation: Defer
-
doOnUnsubscribe
@Experimental public final Single<T> doOnUnsubscribe(Action0 action)
Modifies the sourceSingleso that it invokes the given action when it is unsubscribed from its subscribers.
- Scheduler:
doOnUnsubscribedoes not operate by default on a particularScheduler.
- Parameters:
action- the action that gets called when thisSingleis unsubscribed.- Returns:
- the source
Singlemodified so as to call this Action when appropriate. - See Also:
- ReactiveX operators documentation: Do
-
doAfterTerminate
@Experimental public final Single<T> doAfterTerminate(Action0 action)
Registers anAction0to be called when thisSingleinvokes eitherSingleSubscriber.onSuccess(Object)onSuccess} oronError.
- Scheduler:
doAfterTerminatedoes not operate by default on a particularScheduler.
-
iterableToArray
static <T> Single<? extends T>[] iterableToArray(java.lang.Iterable<? extends Single<? extends T>> singlesIterable)
-
retry
public final Single<T> retry()
Returns a Single that mirrors the source Single, resubscribing to it if it callsonError(infinite retry count).
If the source Single calls SingleSubscriber.onError(java.lang.Throwable), this method will resubscribe to the source Single rather than propagating theonErrorcall.- Scheduler:
retryoperates by default on thetrampolineScheduler.
- Returns:
- the source Single modified with retry logic
- See Also:
- ReactiveX operators documentation: Retry
-
retry
public final Single<T> retry(long count)
Returns an Single that mirrors the source Single, resubscribing to it if it callsonErrorup 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 ofcountresubscriptions rather than propagating theonErrorcall.- Scheduler:
retryoperates by default on thetrampolineScheduler.
- Parameters:
count- number of retry attempts before failing- Returns:
- the source Single modified with retry logic
- See Also:
- ReactiveX operators documentation: Retry
-
retry
public final Single<T> retry(Func2<java.lang.Integer,java.lang.Throwable,java.lang.Boolean> predicate)
Returns an Single that mirrors the source Single, resubscribing to it if it callsonErrorand the predicate returns true for that specific exception and retry count.
- Backpressure Support:
- This operator honors backpressure.
- Scheduler:
retryoperates by default on thetrampolineScheduler.
- Parameters:
predicate- the predicate that determines if a resubscription may happen in case of a specific exception and retry count- Returns:
- the source Single modified with retry logic
- See Also:
retry(), ReactiveX operators documentation: Retry
-
retryWhen
public final 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 anonError. AnonErrornotification from the source will result in the emission of aThrowableitem to the Observable provided as an argument to thenotificationHandlerfunction.Emissions from the handler
Observableis treated as follows:- If the handler
Observableemits anonCompletedtheretryWhenwill callonErrorwithNoSuchElementExceptionon the child subscription. - If the handler
Observableemits anonErrortheretryWhenwill callonErrorwith the same Throwable instance on the child subscription. - Otherwise, the operator will resubscribe to the source Single.
The
notificationHandlerfunction 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
Observableprovided in the function call because expects an emission of the exception to be matched by an event from the handler Observable.
- Scheduler:
retryWhenoperates by default on thetrampolineScheduler.
- Parameters:
notificationHandler- receives an Observable of notifications with which a user can complete or error, aborting the retry- Returns:
- the source Single modified with retry logic
- See Also:
- ReactiveX operators documentation: Retry
- If the handler
-
using
@Experimental public static <T,Resource> Single<T> using(Func0<Resource> resourceFactory, Func1<? super Resource,? extends Single<? extends T>> singleFactory, Action1<? super Resource> disposeAction)
Constructs an Single that creates a dependent resource object which is disposed of on unsubscription.
- Scheduler:
usingdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type of the generated sourceResource- the type of the per-subscriber resource- Parameters:
resourceFactory- 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 resource- Returns:
- the Single whose lifetime controls the lifetime of the dependent resource object
- See Also:
- ReactiveX operators documentation: Using
-
using
@Experimental public static <T,Resource> Single<T> using(Func0<Resource> resourceFactory, Func1<? super Resource,? extends Single<? extends T>> singleFactory, Action1<? super Resource> disposeAction, boolean disposeEagerly)
Constructs an Single that creates a dependent resource object which is disposed of just before termination if you have setdisposeEagerlytotrueand 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.disposeActionwill only be called once per subscription.
- Scheduler:
usingdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type of the generated sourceResource- the type of the per-subscriber resource- Parameters:
resourceFactory- 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- iftruethen disposal will happen either on unsubscription or just before emission of a terminal event (onCompleteoronError).- Returns:
- the Single whose lifetime controls the lifetime of the dependent resource object
- Since:
- (if this graduates from Experimental/Beta to supported, replace this parenthetical with the release number)
- See Also:
- ReactiveX operators documentation: Using
-
delaySubscription
@Experimental public final Single<T> delaySubscription(Observable<?> other)
Returns a Single that delays the subscription to this Single until the Observable completes. In case theonErrorof the supplied observer throws, the exception will be propagated to the downstream subscriber and will result in skipping the subscription of this Single.- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Parameters:
other- the Observable that should trigger the subscription to this Single.- Returns:
- a Single that delays the subscription to this Single until the Observable emits an element or completes normally.
-
-