Class Single<T>
- java.lang.Object
-
- io.servicetalk.concurrent.api.Single<T>
-
- Type Parameters:
T- Type of the result of the single.
- Direct Known Subclasses:
LegacyTestSingle,SubscribableSingle,TestSingle
public abstract class Single<T> extends java.lang.ObjectAn asynchronous computation that either completes with success giving the result or completes with an error.How to subscribe?
This class does not provide a way to subscribe using aSingleSource.Subscriberas such calls are ambiguous about the intent whether the subscribe is part of the same source (a.k.a an operator) or it is a terminal subscribe. If it is required to subscribe to a source, then asource adaptercan be used to convert to aSingleSource.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedSingle()New instance.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Single<T>afterCancel(java.lang.Runnable onCancel)Invokes theonCancelRunnableargument afterCancellable.cancel()is called for Subscriptions of the returnedSingle.Single<T>afterFinally(SingleTerminalSignalConsumer<? super T> doFinally)Invokes the corresponding method onafterFinallySingleTerminalSignalConsumerargument after any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)- invokesSingleTerminalSignalConsumer.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)- invokesSingleTerminalSignalConsumer.onError(Throwable)Cancellable.cancel()- invokesSingleTerminalSignalConsumer.cancel()for Subscriptions/SingleSource.Subscribers of the returnedSingle.Single<T>afterFinally(TerminalSignalConsumer doFinally)Invokes the corresponding method onafterFinallyTerminalSignalConsumerargument after any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)- invokesTerminalSignalConsumer.onComplete()SingleSource.Subscriber.onError(Throwable)- invokesTerminalSignalConsumer.onError(Throwable)Cancellable.cancel()- invokesTerminalSignalConsumer.cancel()for Subscriptions/SingleSource.Subscribers of the returnedSingle.Single<T>afterFinally(java.lang.Runnable doFinally)Invokes thewhenFinallyRunnableargument after any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)Cancellable.cancel()for Subscriptions/SingleSource.Subscribers of the returnedSingle.Single<T>afterOnError(java.util.function.Consumer<java.lang.Throwable> onError)Invokes theonErrorConsumerargument afterSingleSource.Subscriber.onError(Throwable)is called forSingleSource.Subscribers of the returnedSingle.Single<T>afterOnSubscribe(java.util.function.Consumer<Cancellable> onSubscribe)Invokes theonSubscribeConsumerargument afterSingleSource.Subscriber.onSubscribe(Cancellable)is called forSingleSource.Subscribers of the returnedSingle.Single<T>afterOnSuccess(java.util.function.Consumer<? super T> onSuccess)Invokes theonSuccessConsumerargument afterSingleSource.Subscriber.onSuccess(Object)is called forSingleSource.Subscribers of the returnedSingle.Single<T>afterSubscriber(java.util.function.Supplier<? extends SingleSource.Subscriber<? super T>> subscriberSupplier)Creates a newSingleSource.Subscriber(via thesubscriberSupplierargument) on each call to subscribe and invokes all theSingleSource.Subscribermethods after theSingleSource.Subscribers of the returnedSingle.static <T> Single<T>amb(Single<? extends T>... singles)Creates a newSinglethat terminates with the result (either success or error) of whichever amongst the passedsinglesthat terminates first.static <T> Single<T>amb(java.lang.Iterable<Single<? extends T>> singles)Creates a newSinglethat terminates with the result (either success or error) of whichever amongst the passedsinglesthat terminates first.Single<T>ambWith(Single<T> other)static <T> Single<T>anyOf(Single<? extends T>... singles)Creates a newSinglethat terminates with the result (either success or error) of whichever amongst the passedsinglesthat terminates first.static <T> Single<T>anyOf(java.lang.Iterable<Single<? extends T>> singles)Creates a newSinglethat terminates with the result (either success or error) of whichever amongst the passedsinglesthat terminates first.Single<T>beforeCancel(java.lang.Runnable onCancel)Invokes theonCancelRunnableargument beforeCancellable.cancel()is called for Subscriptions of the returnedSingle.Single<T>beforeFinally(SingleTerminalSignalConsumer<? super T> doFinally)Invokes the corresponding method onbeforeFinallySingleTerminalSignalConsumerargument before any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)- invokesSingleTerminalSignalConsumer.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)- invokesSingleTerminalSignalConsumer.onError(Throwable)Cancellable.cancel()- invokesSingleTerminalSignalConsumer.cancel()for Subscriptions/SingleSource.Subscribers of the returnedSingle.Single<T>beforeFinally(TerminalSignalConsumer doFinally)Invokes the corresponding method onbeforeFinallyTerminalSignalConsumerargument before any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)- invokesTerminalSignalConsumer.onComplete()SingleSource.Subscriber.onError(Throwable)- invokesTerminalSignalConsumer.onError(Throwable)Cancellable.cancel()- invokesTerminalSignalConsumer.cancel()for Subscriptions/SingleSource.Subscribers of the returnedSingle.Single<T>beforeFinally(java.lang.Runnable doFinally)Invokes thewhenFinallyRunnableargument before any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)Cancellable.cancel()for Subscriptions/SingleSource.Subscribers of the returnedSingle.Single<T>beforeOnError(java.util.function.Consumer<java.lang.Throwable> onError)Invokes theonErrorConsumerargument beforeSingleSource.Subscriber.onError(Throwable)is called forSingleSource.Subscribers of the returnedSingle.Single<T>beforeOnSubscribe(java.util.function.Consumer<Cancellable> onSubscribe)Invokes theonSubscribeConsumerargument beforeSingleSource.Subscriber.onSubscribe(Cancellable)is called forSingleSource.Subscribers of the returnedSingle.Single<T>beforeOnSuccess(java.util.function.Consumer<? super T> onSuccess)Invokes theonSuccessConsumerargument beforeSingleSource.Subscriber.onSuccess(Object)is called forSingleSource.Subscribers of the returnedSingle.Single<T>beforeSubscriber(java.util.function.Supplier<? extends SingleSource.Subscriber<? super T>> subscriberSupplier)Creates a newSingleSource.Subscriber(via thesubscriberSupplierargument) on each call to subscribe and invokes all theSingleSource.Subscribermethods before theSingleSource.Subscribers of the returnedSingle.static <T> Single<java.util.Collection<T>>collectUnordered(int maxConcurrency, Single<? extends T>... singles)Asynchronously collects results of the passedSingles into a singleCollection.static <T> Single<java.util.Collection<T>>collectUnordered(Single<? extends T>... singles)Asynchronously collects results of the passedSingles into a singleCollection.static <T> Single<java.util.Collection<T>>collectUnordered(java.lang.Iterable<? extends Single<? extends T>> singles)Asynchronously collects results of individualSingles returned by the passedIterableinto a singleCollection.static <T> Single<java.util.Collection<T>>collectUnordered(java.lang.Iterable<? extends Single<? extends T>> singles, int maxConcurrency)Asynchronously collects results of individualSingles returned by the passedIterableinto a singleCollection.static <T> Single<java.util.Collection<T>>collectUnorderedDelayError(int maxConcurrency, Single<? extends T>... singles)Asynchronously collects results of the passedSingles into a singleCollection.static <T> Single<java.util.Collection<T>>collectUnorderedDelayError(Single<? extends T>... singles)Asynchronously collects results of the passedSingles into a singleCollection.static <T> Single<java.util.Collection<T>>collectUnorderedDelayError(java.lang.Iterable<? extends Single<? extends T>> singles)Asynchronously collects results of individualSingles returned by the passedIterableinto a singleCollection.static <T> Single<java.util.Collection<T>>collectUnorderedDelayError(java.lang.Iterable<? extends Single<? extends T>> singles, int maxConcurrency)Asynchronously collects results of individualSingles returned by the passedIterableinto a singleCollection.Single<T>concat(Completable next)Returns aSinglethat emits the result of thisSingleafternextCompletableterminates successfully.Publisher<T>concat(Publisher<? extends T> next)Publisher<T>concat(Single<? extends T> next)static <T> Single<T>defer(java.util.function.Supplier<? extends Single<? extends T>> singleSupplier)Defer creation of aSingletill it is subscribed to.static <T> Single<T>failed(java.lang.Throwable cause)Creates a realizedSinglewhich always completes with the provided errorcause.<R> Single<R>flatMap(java.util.function.Function<? super T,? extends Single<? extends R>> next)CompletableflatMapCompletable(java.util.function.Function<? super T,? extends Completable> next)<R> Publisher<R>flatMapPublisher(java.util.function.Function<? super T,? extends Publisher<? extends R>> next)static <T> Single<T>fromCallable(java.util.concurrent.Callable<T> callable)static <T> Single<T>fromFuture(java.util.concurrent.Future<? extends T> future)static <T> Single<T>fromStage(java.util.concurrent.CompletionStage<? extends T> stage)Convert from aCompletionStageto aSingle.static <T> Single<T>fromSupplier(java.util.function.Supplier<T> supplier)protected abstract voidhandleSubscribe(SingleSource.Subscriber<? super T> subscriber)Handles a subscriber to thisSingle.Single<T>idleTimeout(long duration, java.util.concurrent.TimeUnit unit)Deprecated.Single<T>idleTimeout(long duration, java.util.concurrent.TimeUnit unit, Executor timeoutExecutor)Deprecated.Single<T>idleTimeout(java.time.Duration duration)Deprecated.Usetimeout(Duration).Single<T>idleTimeout(java.time.Duration duration, Executor timeoutExecutor)Deprecated.CompletableignoreElement()Ignores the result of thisSingleand forwards the termination signal to the returnedCompletable.<R> Single<R>liftAsync(SingleOperator<? super T,? extends R> operator)This method requires advanced knowledge of building operators.<R> Single<R>liftSync(SingleOperator<? super T,? extends R> operator)This method requires advanced knowledge of building operators.<R> Single<R>map(java.util.function.Function<? super T,? extends R> mapper)Maps the result of this single to a different type.static <T> Single<T>never()Creates aSinglethat never terminates.<E extends java.lang.Throwable>
Single<T>onErrorMap(java.lang.Class<E> type, java.util.function.Function<? super E,? extends java.lang.Throwable> mapper)Transform errors emitted on thisSinglewhich matchtypeinto a different error.Single<T>onErrorMap(java.util.function.Function<? super java.lang.Throwable,? extends java.lang.Throwable> mapper)Transform errors emitted on thisSingleinto a different error.Single<T>onErrorMap(java.util.function.Predicate<? super java.lang.Throwable> predicate, java.util.function.Function<? super java.lang.Throwable,? extends java.lang.Throwable> mapper)Transform errors emitted on thisSinglewhich matchpredicateinto a different error.<E extends java.lang.Throwable>
Single<T>onErrorResume(java.lang.Class<E> type, java.util.function.Function<? super E,? extends Single<? extends T>> nextFactory)Single<T>onErrorResume(java.util.function.Function<? super java.lang.Throwable,? extends Single<? extends T>> nextFactory)Single<T>onErrorResume(java.util.function.Predicate<? super java.lang.Throwable> predicate, java.util.function.Function<? super java.lang.Throwable,? extends Single<? extends T>> nextFactory)<E extends java.lang.Throwable>
Single<T>onErrorReturn(java.lang.Class<E> type, java.util.function.Function<? super E,? extends T> itemSupplier)Transform errors emitted on thisSinglewhich matchtypeintoSingleSource.Subscriber.onSuccess(Object)signal (e.g.Single<T>onErrorReturn(java.util.function.Function<? super java.lang.Throwable,? extends T> itemSupplier)Transform errors emitted on thisSingleintoSingleSource.Subscriber.onSuccess(Object)signal (e.g.Single<T>onErrorReturn(java.util.function.Predicate<? super java.lang.Throwable> predicate, java.util.function.Function<? super java.lang.Throwable,? extends T> itemSupplier)Transform errors emitted on thisSinglewhich matchpredicateintoSingleSource.Subscriber.onSuccess(Object)signal (e.g.Single<T>publishAndSubscribeOn(Executor executor)Creates a newSinglethat will use the passedExecutorto invoke the following methods: AllSingleSource.Subscribermethods. AllCancellablemethods. ThehandleSubscribe(SingleSource.Subscriber)method. This method does not override precedingExecutors, if any, specified forthisSingle.Single<T>publishAndSubscribeOnOverride(Executor executor)Creates a newSinglethat will use the passedExecutorto invoke the following methods: AllSingleSource.Subscribermethods. AllCancellablemethods. ThehandleSubscribe(SingleSource.Subscriber)method. This method overrides precedingExecutors, if any, specified forthisSingle.Single<T>publishOn(Executor executor)Creates a newSinglethat will use the passedExecutorto invoke allSingleSource.Subscribermethods.Single<T>publishOnOverride(Executor executor)Creates a newSinglethat will use the passedExecutorto invoke allSingleSource.Subscribermethods.Single<T>recoverWith(java.util.function.Function<? super java.lang.Throwable,? extends Single<? extends T>> nextFactory)Deprecated.Publisher<T>repeat(java.util.function.IntPredicate shouldRepeat)Publisher<T>repeatWhen(java.util.function.IntFunction<? extends Completable> repeatWhen)Re-subscribes to thisSinglewhen it completes and theCompletablereturned by the suppliedIntFunctioncompletes successfully.Single<T>retry(BiIntPredicate<java.lang.Throwable> shouldRetry)Single<T>retryWhen(BiIntFunction<java.lang.Throwable,? extends Completable> retryWhen)Re-subscribes to thisSingleif an error is emitted and theCompletablereturned by the suppliedBiIntFunctioncompletes successfully.Cancellablesubscribe(java.util.function.Consumer<? super T> resultConsumer)Subscribe to thisSingle, emits the result to the passedConsumerand log anySingleSource.Subscriber.onError(Throwable).protected voidsubscribeInternal(SingleSource.Subscriber<? super T> subscriber)A internal subscribe method similar toSingleSource.subscribe(Subscriber)which can be used by different implementations to subscribe.Single<T>subscribeOn(Executor executor)Creates a newSinglethat will use the passedExecutorto invoke the following methods: AllCancellablemethods. ThehandleSubscribe(SingleSource.Subscriber)method. This method does not override precedingExecutors, if any, specified forthisSingle.Single<T>subscribeOnOverride(Executor executor)Creates a newSinglethat will use the passedExecutorto invoke the following methods: AllCancellablemethods. ThehandleSubscribe(SingleSource.Subscriber)method. This method overrides precedingExecutors, if any, specified forthisSingle.Single<T>subscribeShareContext()Signifies that when the returnedSingleis subscribed to, theAsyncContextwill be shared instead of making acopy.static <T> Single<T>succeeded(T value)Creates a realizedSinglewhich always completes successfully with the providedvalue.Single<T>timeout(long duration, java.util.concurrent.TimeUnit unit)Single<T>timeout(long duration, java.util.concurrent.TimeUnit unit, Executor timeoutExecutor)Single<T>timeout(java.time.Duration duration)Single<T>timeout(java.time.Duration duration, Executor timeoutExecutor)CompletabletoCompletable()Ignores the result of thisSingleand forwards the termination signal to the returnedCompletable.java.util.concurrent.CompletionStage<T>toCompletionStage()Convert thisSingleto aCompletionStage.java.util.concurrent.Future<T>toFuture()Convert thisSingleto aFuture.Publisher<T>toPublisher()Converts thisSingleto aPublisher.Single<T>whenCancel(java.lang.Runnable onCancel)Invokes theonCancelRunnableargument whenCancellable.cancel()is called for Subscriptions of the returnedSingle.Single<T>whenFinally(SingleTerminalSignalConsumer<? super T> doFinally)Invokes the corresponding method onwhenFinallySingleTerminalSignalConsumerargument when any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)- invokesSingleTerminalSignalConsumer.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)- invokesSingleTerminalSignalConsumer.onError(Throwable)Cancellable.cancel()- invokesSingleTerminalSignalConsumer.cancel()for Subscriptions/SingleSource.Subscribers of the returnedSingle.Single<T>whenFinally(TerminalSignalConsumer doFinally)Invokes the corresponding method onwhenFinallyTerminalSignalConsumerargument when any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)- invokesTerminalSignalConsumer.onComplete()SingleSource.Subscriber.onError(Throwable)- invokesTerminalSignalConsumer.onError(Throwable)Cancellable.cancel()- invokesTerminalSignalConsumer.cancel()for Subscriptions/SingleSource.Subscribers of the returnedSingle.Single<T>whenFinally(java.lang.Runnable doFinally)Invokes thewhenFinallyRunnableargument exactly once, when any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)Cancellable.cancel()for Subscriptions/SingleSource.Subscribers of the returnedSingle.Single<T>whenOnError(java.util.function.Consumer<java.lang.Throwable> onError)Invokes theonErrorConsumerargument whenSingleSource.Subscriber.onError(Throwable)is called forSingleSource.Subscribers of the returnedSingle.Single<T>whenOnSubscribe(java.util.function.Consumer<Cancellable> onSubscribe)Invokes theonSubscribeConsumerargument whenSingleSource.Subscriber.onSubscribe(Cancellable)is called forSingleSource.Subscribers of the returnedSingle.Single<T>whenOnSuccess(java.util.function.Consumer<? super T> onSuccess)Invokes theonSuccessConsumerargument whenSingleSource.Subscriber.onSuccess(Object)is called forSingleSource.Subscribers of the returnedSingle.Single<T>whenSubscriber(java.util.function.Supplier<? extends SingleSource.Subscriber<? super T>> subscriberSupplier)Creates a newSingleSource.Subscriber(via thesubscriberSupplierargument) for each new subscribe and invokes methods on thatSingleSource.Subscriberwhen the corresponding methods are called forSingleSource.Subscribers of the returnedSingle.static <T1,T2,T3,R>
Single<R>zip(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Function3<? super T1,? super T2,? super T3,? extends R> zipper)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, Function4<? super T1,? super T2,? super T3,? super T4,? extends R> zipper)static <T1,T2,R>
Single<R>zip(Single<? extends T1> s1, Single<? extends T2> s2, java.util.function.BiFunction<? super T1,? super T2,? extends R> zipper)Create a newSinglethat emits the results of a specified zipperBiFunctionto items emitted bysingles.static <R> Single<R>zip(java.util.function.Function<? super java.lang.Object[],? extends R> zipper, Single<?>... singles)Create a newSinglethat emits the results of a specified zipperFunctionto items emitted bysingles.<T2,R>
Single<R>zipWith(Single<? extends T2> other, java.util.function.BiFunction<? super T,? super T2,? extends R> zipper)Create a newSinglethat emits the results of a specified zipperBiFunctionto items emitted bysingles.
-
-
-
Method Detail
-
map
public final <R> Single<R> map(java.util.function.Function<? super T,? extends R> mapper)
Maps the result of this single to a different type. Error, if any is forwarded to the returnedSingle.This method provides a data transformation in sequential programming similar to:
T tResult = resultOfThisSingle(); R rResult = mapper.apply(tResult);
-
onErrorReturn
public final Single<T> onErrorReturn(java.util.function.Function<? super java.lang.Throwable,? extends T> itemSupplier)
Transform errors emitted on thisSingleintoSingleSource.Subscriber.onSuccess(Object)signal (e.g. swallows the error).This method provides a data transformation in sequential programming similar to:
T result = resultOfThisSingle(); try { terminalOfThisSingle(); } catch (Throwable cause) { return itemSupplier.apply(cause); } return result;- Parameters:
itemSupplier- returns the element to emit toSingleSource.Subscriber.onSuccess(Object).- Returns:
- A
Singlewhich transform errors emitted on thisSingleintoSingleSource.Subscriber.onSuccess(Object)signal (e.g. swallows the error). - See Also:
- ReactiveX catch operator.
-
onErrorReturn
public final <E extends java.lang.Throwable> Single<T> onErrorReturn(java.lang.Class<E> type, java.util.function.Function<? super E,? extends T> itemSupplier)
Transform errors emitted on thisSinglewhich matchtypeintoSingleSource.Subscriber.onSuccess(Object)signal (e.g. swallows the error).This method provides a data transformation in sequential programming similar to:
T result = resultOfThisSingle(); try { terminalOfThisSingle(); } catch (Throwable cause) { if (!type.isInstance(cause)) { throw cause; } return itemSupplier.apply(cause); } return result;- Type Parameters:
E- The type ofThrowableto transform.- Parameters:
type- TheThrowabletype to filter, operator will not apply for errors which don't match this type.itemSupplier- returns the element to emit toSingleSource.Subscriber.onSuccess(Object).- Returns:
- A
Singlewhich transform errors emitted on thisSingleintoSingleSource.Subscriber.onSuccess(Object)signal (e.g. swallows the error). - See Also:
- ReactiveX catch operator.
-
onErrorReturn
public final Single<T> onErrorReturn(java.util.function.Predicate<? super java.lang.Throwable> predicate, java.util.function.Function<? super java.lang.Throwable,? extends T> itemSupplier)
Transform errors emitted on thisSinglewhich matchpredicateintoSingleSource.Subscriber.onSuccess(Object)signal (e.g. swallows the error).This method provides a data transformation in sequential programming similar to:
T result = resultOfThisSingle(); try { terminalOfThisSingle(); } catch (Throwable cause) { if (!predicate.test(cause)) { throw cause; } return itemSupplier.apply(cause); } return result;- Parameters:
predicate- returnstrueif theThrowableshould be transformed toSingleSource.Subscriber.onSuccess(Object)signal. Returnsfalseto propagate the error.itemSupplier- returns the element to emit toSingleSource.Subscriber.onSuccess(Object).- Returns:
- A
Singlewhich transform errors emitted on thisSingleintoSingleSource.Subscriber.onSuccess(Object)signal (e.g. swallows the error). - See Also:
- ReactiveX catch operator.
-
onErrorMap
public final Single<T> onErrorMap(java.util.function.Function<? super java.lang.Throwable,? extends java.lang.Throwable> mapper)
Transform errors emitted on thisSingleinto a different error.This method provides a data transformation in sequential programming similar to:
T result = resultOfThisSingle(); try { terminalOfThisSingle(); } catch (Throwable cause) { throw mapper.apply(cause); } return result;- Parameters:
mapper- returns the error used to terminate the returnedSingle.- Returns:
- A
Singlewhich transform errors emitted on thisSingleinto a different error. - See Also:
- ReactiveX catch operator.
-
onErrorMap
public final <E extends java.lang.Throwable> Single<T> onErrorMap(java.lang.Class<E> type, java.util.function.Function<? super E,? extends java.lang.Throwable> mapper)
Transform errors emitted on thisSinglewhich matchtypeinto a different error.This method provides a data transformation in sequential programming similar to:
T result = resultOfThisSingle(); try { terminalOfThisSingle(); } catch (Throwable cause) { if (type.isInstance(cause)) { throw mapper.apply(cause); } else { throw cause; } } return result;- Type Parameters:
E- The type ofThrowableto transform.- Parameters:
type- TheThrowabletype to filter, operator will not apply for errors which don't match this type.mapper- returns the error used to terminate the returnedSingle.- Returns:
- A
Singlewhich transform errors emitted on thisSingleinto a different error. - See Also:
- ReactiveX catch operator.
-
onErrorMap
public final Single<T> onErrorMap(java.util.function.Predicate<? super java.lang.Throwable> predicate, java.util.function.Function<? super java.lang.Throwable,? extends java.lang.Throwable> mapper)
Transform errors emitted on thisSinglewhich matchpredicateinto a different error.This method provides a data transformation in sequential programming similar to:
T results = resultOfThisSingle(); try { terminalOfThisSingle(); } catch (Throwable cause) { if (predicate.test(cause)) { throw mapper.apply(cause); } else { throw cause; } } return result;- Parameters:
predicate- returnstrueif theThrowableshould be transformed viamapper. Returnsfalseto propagate the original error.mapper- returns the error used to terminate the returnedSingle.- Returns:
- A
Singlewhich transform errors emitted on thisSingleinto a different error. - See Also:
- ReactiveX catch operator.
-
onErrorResume
public final Single<T> onErrorResume(java.util.function.Function<? super java.lang.Throwable,? extends Single<? extends T>> nextFactory)
Recover from any error emitted by thisSingleby using anotherSingleprovided by the passednextFactory.This method provides similar capabilities to a try/catch block in sequential programming:
T result; try { result = resultOfThisSingle(); } catch (Throwable cause) { // Note that nextFactory returning a error Single is like re-throwing (nextFactory shouldn't throw). result = nextFactory.apply(cause); } return result;
-
onErrorResume
public final <E extends java.lang.Throwable> Single<T> onErrorResume(java.lang.Class<E> type, java.util.function.Function<? super E,? extends Single<? extends T>> nextFactory)
Recover from errors emitted by thisSinglewhich matchtypeby using anotherSingleprovided by the passednextFactory.This method provides similar capabilities to a try/catch block in sequential programming:
T result; try { result = resultOfThisSingle(); } catch (Throwable cause) { if (type.isInstance(cause)) { // Note that nextFactory returning a error Single is like re-throwing (nextFactory shouldn't throw). result = nextFactory.apply(cause); } else { throw cause; } } return result;- Type Parameters:
E- The type ofThrowableto transform.- Parameters:
type- TheThrowabletype to filter, operator will not apply for errors which don't match this type.nextFactory- Returns the nextSingle, when thisSingleemits an error.- Returns:
- A
Singlethat recovers from an error from thisSingleby using anotherSingleprovided by the passednextFactory. - See Also:
- ReactiveX catch operator.
-
onErrorResume
public final Single<T> onErrorResume(java.util.function.Predicate<? super java.lang.Throwable> predicate, java.util.function.Function<? super java.lang.Throwable,? extends Single<? extends T>> nextFactory)
Recover from errors emitted by thisSinglewhich matchpredicateby using anotherSingleprovided by the passednextFactory.This method provides similar capabilities to a try/catch block in sequential programming:
T result; try { result = resultOfThisSingle(); } catch (Throwable cause) { if (predicate.test(cause)) { // Note that nextFactory returning a error Single is like re-throwing (nextFactory shouldn't throw). result = nextFactory.apply(cause); } else { throw cause; } } return result;- Parameters:
predicate- returnstrueif theThrowableshould be transformed vianextFactory. Returnsfalseto propagate the original error.nextFactory- Returns the nextSingle, when thisSingleemits an error.- Returns:
- A
Singlethat recovers from an error from thisSingleby using anotherSingleprovided by the passednextFactory. - See Also:
- ReactiveX catch operator.
-
recoverWith
@Deprecated public final Single<T> recoverWith(java.util.function.Function<? super java.lang.Throwable,? extends Single<? extends T>> nextFactory)
Deprecated.Recover from any error emitted by thisSingleby using anotherSingleprovided by the passednextFactory.This method provides similar capabilities to a try/catch block in sequential programming:
T result; try { result = resultOfThisSingle(); } catch (Throwable cause) { // Note that nextFactory returning a error Single is like re-throwing (nextFactory shouldn't throw). result = nextFactory.apply(cause); } return result;
-
flatMap
public final <R> Single<R> flatMap(java.util.function.Function<? super T,? extends Single<? extends R>> next)
Returns aSinglethat mirrors emissions from theSinglereturned bynext. Any error emitted by thisSingleis forwarded to the returnedSingle.This method is similar to
map(Function)but the result is asynchronous, and provides a data transformation in sequential programming similar to:T tResult = resultOfThisSingle(); R rResult = mapper.apply(tResult); // Asynchronous result is flatten into a value by this operator.
-
flatMapCompletable
public final Completable flatMapCompletable(java.util.function.Function<? super T,? extends Completable> next)
Returns aCompletablethat mirrors emissions from theCompletablereturned bynext. Any error emitted by thisSingleis forwarded to the returnedCompletable.This method is similar to
map(Function)but the result is asynchronous with either complete/error status in sequential programming similar to:T tResult = resultOfThisSingle(); mapper.apply(tResult); // Asynchronous result is flatten into a error or completion by this operator.- Parameters:
next- Function to give the nextCompletable.- Returns:
- New
Completablethat switches to theCompletablereturned bynextafter thisSinglecompletes successfully.
-
flatMapPublisher
public final <R> Publisher<R> flatMapPublisher(java.util.function.Function<? super T,? extends Publisher<? extends R>> next)
Returns aPublisherthat mirrors emissions from thePublisherreturned bynext. Any error emitted by thisSingleis forwarded to the returnedPublisher.This method is similar to
map(Function)but the result is asynchronous, and provides a data transformation in sequential programming similar to:T tResult = resultOfThisSingle(); // Asynchronous result from mapper is flatten into collection of values. for (R rResult : mapper.apply(tResult)) { // process rResult }
-
whenOnSuccess
public final Single<T> whenOnSuccess(java.util.function.Consumer<? super T> onSuccess)
Invokes theonSuccessConsumerargument whenSingleSource.Subscriber.onSuccess(Object)is called forSingleSource.Subscribers of the returnedSingle.The order in which
onSuccesswill be invoked relative toSingleSource.Subscriber.onSuccess(Object)is undefined. If you need strict ordering seebeforeOnSuccess(Consumer)andafterOnSuccess(Consumer).From a sequential programming point of view this method is roughly equivalent to the following:
T result = resultOfThisSingle(); // NOTE: The order of operations here is not guaranteed by this method! nextOperation(result); onSuccess.accept(result);- Parameters:
onSuccess- Invoked whenSingleSource.Subscriber.onSuccess(Object)is called forSingleSource.Subscribers of the returnedSingle. MUST NOT throw.- Returns:
- The new
Single. - See Also:
beforeOnSuccess(Consumer),afterOnSuccess(Consumer)
-
whenOnError
public final Single<T> whenOnError(java.util.function.Consumer<java.lang.Throwable> onError)
Invokes theonErrorConsumerargument whenSingleSource.Subscriber.onError(Throwable)is called forSingleSource.Subscribers of the returnedSingle.The order in which
onErrorwill be invoked relative toSingleSource.Subscriber.onError(Throwable)is undefined. If you need strict ordering seebeforeOnError(Consumer)andafterOnError(Consumer).From a sequential programming point of view this method is roughly equivalent to the following:
try { T result = resultOfThisSingle(); } catch (Throwable cause) { // NOTE: The order of operations here is not guaranteed by this method! nextOperation(cause); onError.accept(cause); }- Parameters:
onError- Invoked whenSingleSource.Subscriber.onError(Throwable)is called forSingleSource.Subscribers of the returnedSingle. MUST NOT throw.- Returns:
- The new
Single. - See Also:
beforeOnError(Consumer),afterOnError(Consumer)
-
whenFinally
public final Single<T> whenFinally(java.lang.Runnable doFinally)
Invokes thewhenFinallyRunnableargument exactly once, when any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)Cancellable.cancel()
SingleSource.Subscribers of the returnedSingle.The order in which
whenFinallywill be invoked relative to the above methods is undefined. If you need strict ordering seebeforeFinally(Runnable)andafterFinally(Runnable).From a sequential programming point of view this method is roughly equivalent to the following:
try { T result = resultOfThisSingle(); } finally { // NOTE: The order of operations here is not guaranteed by this method! nextOperation(); // Maybe notifying of cancellation, or termination doFinally.run(); }- Parameters:
doFinally- Invoked exactly once, when any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)Cancellable.cancel()
SingleSource.Subscribers of the returnedSingle. MUST NOT throw.- Returns:
- The new
Single. - See Also:
beforeFinally(Runnable),afterFinally(Runnable)
-
whenFinally
public final Single<T> whenFinally(TerminalSignalConsumer doFinally)
Invokes the corresponding method onwhenFinallyTerminalSignalConsumerargument when any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)- invokesTerminalSignalConsumer.onComplete()SingleSource.Subscriber.onError(Throwable)- invokesTerminalSignalConsumer.onError(Throwable)Cancellable.cancel()- invokesTerminalSignalConsumer.cancel()
SingleSource.Subscribers of the returnedSingle.The order in which
whenFinallywill be invoked relative to the above methods is undefined. If you need strict ordering seebeforeFinally(TerminalSignalConsumer)andafterFinally(TerminalSignalConsumer).From a sequential programming point of view this method is roughly equivalent to the following:
T result; try { result = resultOfThisSingle(); } catch(Throwable t) { // NOTE: The order of operations here is not guaranteed by this method! nextOperation(); // Maybe notifying of cancellation, or termination doFinally.onError(t); return; } // NOTE: The order of operations here is not guaranteed by this method! nextOperation(); // Maybe notifying of cancellation, or termination doFinally.onComplete();- Parameters:
doFinally- For each subscribe of the returnedSingle, at most one method of thisTerminalSignalConsumerwill be invoked.- Returns:
- The new
Single. - See Also:
beforeFinally(TerminalSignalConsumer),afterFinally(TerminalSignalConsumer)
-
whenFinally
public final Single<T> whenFinally(SingleTerminalSignalConsumer<? super T> doFinally)
Invokes the corresponding method onwhenFinallySingleTerminalSignalConsumerargument when any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)- invokesSingleTerminalSignalConsumer.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)- invokesSingleTerminalSignalConsumer.onError(Throwable)Cancellable.cancel()- invokesSingleTerminalSignalConsumer.cancel()
SingleSource.Subscribers of the returnedSingle.The order in which
whenFinallywill be invoked relative to the above methods is undefined. If you need strict ordering seebeforeFinally(SingleTerminalSignalConsumer)andafterFinally(SingleTerminalSignalConsumer).From a sequential programming point of view this method is roughly equivalent to the following:
T result; try { result = resultOfThisSingle(); } catch(Throwable t) { // NOTE: The order of operations here is not guaranteed by this method! nextOperation(); // Maybe notifying of cancellation, or termination doFinally.onError(t); return; } // NOTE: The order of operations here is not guaranteed by this method! nextOperation(); // Maybe notifying of cancellation, or termination doFinally.onSuccess(result);- Parameters:
doFinally- For each subscribe of the returnedSingle, at most one method of thisSingleTerminalSignalConsumerwill be invoked.- Returns:
- The new
Single. - See Also:
beforeFinally(SingleTerminalSignalConsumer),afterFinally(SingleTerminalSignalConsumer)
-
whenCancel
public final Single<T> whenCancel(java.lang.Runnable onCancel)
Invokes theonCancelRunnableargument whenCancellable.cancel()is called for Subscriptions of the returnedSingle.The order in which
whenFinallywill be invoked relative toCancellable.cancel()is undefined. If you need strict ordering seebeforeCancel(Runnable)andafterCancel(Runnable).- Parameters:
onCancel- Invoked whenCancellable.cancel()is called for Subscriptions of the returnedSingle. MUST NOT throw.- Returns:
- The new
Single. - See Also:
beforeCancel(Runnable),afterCancel(Runnable)
-
idleTimeout
@Deprecated public final Single<T> idleTimeout(long duration, java.util.concurrent.TimeUnit unit)
Deprecated.Creates a newSinglethat will mimic the signals of thisSinglebut will terminate with a with aTimeoutExceptionif timedurationelapses between subscribe and termination. The timer starts when the returnedSingleis subscribed.In the event of timeout any
CancellablefromSingleSource.Subscriber.onSubscribe(Cancellable)will becancelledand the associatedSingleSource.Subscriberwill beterminated.- Parameters:
duration- The time duration which is allowed to elapse beforeSingleSource.Subscriber.onSuccess(Object).unit- The units forduration.- Returns:
- a new
Singlethat will mimic the signals of thisSinglebut will terminate with aTimeoutExceptionif timedurationelapses beforeSingleSource.Subscriber.onSuccess(Object). - See Also:
- ReactiveX timeout operator.
-
idleTimeout
@Deprecated public final Single<T> idleTimeout(long duration, java.util.concurrent.TimeUnit unit, Executor timeoutExecutor)
Deprecated.Creates a newSinglethat will mimic the signals of thisSinglebut will terminate with a with aTimeoutExceptionif timedurationelapses between subscribe and termination. The timer starts when the returnedSingleis subscribed.In the event of timeout any
CancellablefromSingleSource.Subscriber.onSubscribe(Cancellable)will becancelledand the associatedSingleSource.Subscriberwill beterminated.- Parameters:
duration- The time duration which is allowed to elapse beforeSingleSource.Subscriber.onSuccess(Object).unit- The units forduration.timeoutExecutor- TheExecutorto use for managing the timer notifications.- Returns:
- a new
Singlethat will mimic the signals of thisSinglebut will terminate with aTimeoutExceptionif timedurationelapses beforeSingleSource.Subscriber.onSuccess(Object). - See Also:
- ReactiveX timeout operator.
-
idleTimeout
@Deprecated public final Single<T> idleTimeout(java.time.Duration duration)
Deprecated.Usetimeout(Duration).Creates a newSinglethat will mimic the signals of thisSinglebut will terminate with a with aTimeoutExceptionif timedurationelapses between subscribe and termination. The timer starts when the returnedSingleis subscribed.In the event of timeout any
CancellablefromSingleSource.Subscriber.onSubscribe(Cancellable)will becancelledand the associatedSingleSource.Subscriberwill beterminated.SingleSource.Subscriberwill viaterminated.- Parameters:
duration- The time duration which is allowed to elapse beforeSingleSource.Subscriber.onSuccess(Object).- Returns:
- a new
Singlethat will mimic the signals of thisSinglebut will terminate with aTimeoutExceptionif timedurationelapses beforeSingleSource.Subscriber.onSuccess(Object). - See Also:
- ReactiveX timeout operator.
-
idleTimeout
@Deprecated public final Single<T> idleTimeout(java.time.Duration duration, Executor timeoutExecutor)
Deprecated.Creates a newSinglethat will mimic the signals of thisSinglebut will terminate with a with aTimeoutExceptionif timedurationelapses between subscribe and termination. The timer starts when the returnedSingleis subscribed.In the event of timeout any
CancellablefromSingleSource.Subscriber.onSubscribe(Cancellable)will becancelledand the associatedSingleSource.Subscriberwill beterminated.- Parameters:
duration- The time duration which is allowed to elapse beforeSingleSource.Subscriber.onSuccess(Object).timeoutExecutor- TheExecutorto use for managing the timer notifications.- Returns:
- a new
Singlethat will mimic the signals of thisSinglebut will terminate with aTimeoutExceptionif timedurationelapses beforeSingleSource.Subscriber.onSuccess(Object). - See Also:
- ReactiveX timeout operator.
-
timeout
public final Single<T> timeout(long duration, java.util.concurrent.TimeUnit unit)
Creates a newSinglethat will mimic the signals of thisSinglebut will terminate with a with aTimeoutExceptionif timedurationelapses between subscribe and termination. The timer starts when the returnedSingleis subscribed.In the event of timeout any
CancellablefromSingleSource.Subscriber.onSubscribe(Cancellable)will becancelledand the associatedSingleSource.Subscriberwill beterminated.- Parameters:
duration- The time duration which is allowed to elapse beforeSingleSource.Subscriber.onSuccess(Object).unit- The units forduration.- Returns:
- a new
Singlethat will mimic the signals of thisSinglebut will terminate with aTimeoutExceptionif timedurationelapses beforeSingleSource.Subscriber.onSuccess(Object). - See Also:
- ReactiveX timeout operator.
-
timeout
public final Single<T> timeout(long duration, java.util.concurrent.TimeUnit unit, Executor timeoutExecutor)
Creates a newSinglethat will mimic the signals of thisSinglebut will terminate with a with aTimeoutExceptionif timedurationelapses between subscribe and termination. The timer starts when the returnedSingleis subscribed.In the event of timeout any
CancellablefromSingleSource.Subscriber.onSubscribe(Cancellable)will becancelledand the associatedSingleSource.Subscriberwill beterminated.- Parameters:
duration- The time duration which is allowed to elapse beforeSingleSource.Subscriber.onSuccess(Object).unit- The units forduration.timeoutExecutor- TheExecutorto use for managing the timer notifications.- Returns:
- a new
Singlethat will mimic the signals of thisSinglebut will terminate with aTimeoutExceptionif timedurationelapses beforeSingleSource.Subscriber.onSuccess(Object). - See Also:
- ReactiveX timeout operator.
-
timeout
public final Single<T> timeout(java.time.Duration duration)
Creates a newSinglethat will mimic the signals of thisSinglebut will terminate with a with aTimeoutExceptionif timedurationelapses between subscribe and termination. The timer starts when the returnedSingleis subscribed.In the event of timeout any
CancellablefromSingleSource.Subscriber.onSubscribe(Cancellable)will becancelledand the associatedSingleSource.Subscriberwill beterminated.SingleSource.Subscriberwill viaterminated.- Parameters:
duration- The time duration which is allowed to elapse beforeSingleSource.Subscriber.onSuccess(Object).- Returns:
- a new
Singlethat will mimic the signals of thisSinglebut will terminate with aTimeoutExceptionif timedurationelapses beforeSingleSource.Subscriber.onSuccess(Object). - See Also:
- ReactiveX timeout operator.
-
timeout
public final Single<T> timeout(java.time.Duration duration, Executor timeoutExecutor)
Creates a newSinglethat will mimic the signals of thisSinglebut will terminate with a with aTimeoutExceptionif timedurationelapses between subscribe and termination. The timer starts when the returnedSingleis subscribed.In the event of timeout any
CancellablefromSingleSource.Subscriber.onSubscribe(Cancellable)will becancelledand the associatedSingleSource.Subscriberwill beterminated.- Parameters:
duration- The time duration which is allowed to elapse beforeSingleSource.Subscriber.onSuccess(Object).timeoutExecutor- TheExecutorto use for managing the timer notifications.- Returns:
- a new
Singlethat will mimic the signals of thisSinglebut will terminate with aTimeoutExceptionif timedurationelapses beforeSingleSource.Subscriber.onSuccess(Object). - See Also:
- ReactiveX timeout operator.
-
concat
public final Publisher<T> concat(Single<? extends T> next)
Returns aPublisherthat first emits the result of thisSingleand then subscribes and emits result ofnextSingle. Any error emitted by thisSingleornextSingleis forwarded to the returnedPublisher.This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
Pair<T, T> p = new Pair<>(); p.first = resultOfThisSingle(); p.second = nextSingle(); return p;
-
concat
public final Single<T> concat(Completable next)
Returns aSinglethat emits the result of thisSingleafternextCompletableterminates successfully.nextCompletablewill only be subscribed to after thisSingleterminates successfully. Any error emitted by thisSingleornextCompletableis forwarded to the returnedSingle.This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
T result = resultOfThisSingle(); nextCompletable(); // Note this either completes successfully, or throws an error. return result;- Parameters:
next-Completableto concat.- Returns:
- New
Singlethat emits the result of thisSingleafternextCompletableterminates successfully.
-
concat
public final Publisher<T> concat(Publisher<? extends T> next)
Returns aPublisherthat first emits the result of thisSingleand then subscribes and emits all elements fromnextPublisher. Any error emitted by thisSingleornextPublisheris forwarded to the returnedPublisher.This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
List<T> results = new ...; results.add(resultOfThisSingle()); results.addAll(nextStream()); return results;
-
zipWith
public final <T2,R> Single<R> zipWith(Single<? extends T2> other, java.util.function.BiFunction<? super T,? super T2,? extends R> zipper)
Create a newSinglethat emits the results of a specified zipperBiFunctionto items emitted bysingles.From a sequential programming point of view this method is roughly equivalent to the following:
CompletableFuture<T> f1 = ...; // this CompletableFuture<T2> other = ...; CompletableFuture.allOf(f1, other).get(); // wait for all futures to complete return zipper.apply(f1.get(), other.get());- Type Parameters:
T2- The type ofother.R- The result type of the zipper.- Parameters:
other- The otherSingleto zip with.zipper- Used to combine the completed results for each item fromsingles.- Returns:
- a new
Singlethat emits the results of a specified zipperBiFunctionto items emitted bysingles. - See Also:
- ReactiveX zip operator.
-
retry
public final Single<T> retry(BiIntPredicate<java.lang.Throwable> shouldRetry)
Re-subscribes to thisSingleif an error is emitted and the passedBiIntPredicatereturnstrue.This method provides a means to retry an operation under certain failure conditions and in sequential programming is similar to:
public T execute() { return execute(0); } private T execute(int attempts) { try { return resultOfThisSingle(); } catch (Throwable cause) { if (shouldRetry.apply(attempts + 1, cause)) { return execute(attempts + 1); } else { throw cause; } } }- Parameters:
shouldRetry-BiIntPredicatethat given the retry count and the most recentThrowableemitted from thisSingledetermines if the operation should be retried.- Returns:
- A
Singlethat emits the result from thisSingleor re-subscribes if an error is emitted and if the passedBiIntPredicatereturnedtrue. - See Also:
- ReactiveX retry operator.
-
retryWhen
public final Single<T> retryWhen(BiIntFunction<java.lang.Throwable,? extends Completable> retryWhen)
Re-subscribes to thisSingleif an error is emitted and theCompletablereturned by the suppliedBiIntFunctioncompletes successfully. If the returnedCompletableemits an error, the returnedSingleterminates with that error.This method provides a means to retry an operation under certain failure conditions in an asynchronous fashion and in sequential programming is similar to:
public T execute() { return execute(0); } private T execute(int attempts) { try { return resultOfThisSingle(); } catch (Throwable cause) { try { shouldRetry.apply(attempts + 1, cause); // Either throws or completes normally execute(attempts + 1); } catch (Throwable ignored) { throw cause; } } }- Parameters:
retryWhen-BiIntFunctionthat given the retry count and the most recentThrowableemitted from thisSinglereturns aCompletable. If thisCompletableemits an error, that error is emitted from the returnedSingle, otherwise, originalSingleis re-subscribed when thisCompletablecompletes.- Returns:
- A
Singlethat emits the result from thisSingleor re-subscribes if an error is emitted andCompletablereturned byBiIntFunctioncompletes successfully. - See Also:
- ReactiveX retry operator.
-
repeat
public final Publisher<T> repeat(java.util.function.IntPredicate shouldRepeat)
Re-subscribes to thisSinglewhen it completes and the passedIntPredicatereturnstrue.This method provides a means to repeat an operation multiple times and in sequential programming is similar to:
List<T> results = new ...; int i = 0; do { results.add(resultOfThisSingle()); } while (shouldRepeat.test(++i)); return results;- Parameters:
shouldRepeat-IntPredicatethat given the repeat count determines if the operation should be repeated.- Returns:
- A
Publisherthat emits all items from thisSingleand from all re-subscriptions whenever the operation is repeated. - See Also:
- ReactiveX repeat operator.
-
repeatWhen
public final Publisher<T> repeatWhen(java.util.function.IntFunction<? extends Completable> repeatWhen)
Re-subscribes to thisSinglewhen it completes and theCompletablereturned by the suppliedIntFunctioncompletes successfully. If the returnedCompletableemits an error, the returnedSingleemits an error.This method provides a means to repeat an operation multiple times when in an asynchronous fashion and in sequential programming is similar to:
List<T> results = new ...; int i = 0; while (true) { results.add(resultOfThisSingle()); try { repeatWhen.apply(++i); // Either throws or completes normally } catch (Throwable cause) { break; } } return results;- Parameters:
repeatWhen-IntFunctionthat given the repeat count returns aCompletable. If thisCompletableemits an error repeat is terminated, otherwise, originalSingleis re-subscribed when thisCompletablecompletes.- Returns:
- A
Publisherthat emits all items from thisSingleand from all re-subscriptions whenever the operation is repeated. - See Also:
- ReactiveX retry operator.
-
beforeOnSubscribe
public final Single<T> beforeOnSubscribe(java.util.function.Consumer<Cancellable> onSubscribe)
Invokes theonSubscribeConsumerargument beforeSingleSource.Subscriber.onSubscribe(Cancellable)is called forSingleSource.Subscribers of the returnedSingle.- Parameters:
onSubscribe- Invoked beforeSingleSource.Subscriber.onSubscribe(Cancellable)is called forSingleSource.Subscribers of the returnedSingle. MUST NOT throw.- Returns:
- The new
Single.
-
beforeOnSuccess
public final Single<T> beforeOnSuccess(java.util.function.Consumer<? super T> onSuccess)
Invokes theonSuccessConsumerargument beforeSingleSource.Subscriber.onSuccess(Object)is called forSingleSource.Subscribers of the returnedSingle.From a sequential programming point of view this method is roughly equivalent to the following:
T result = resultOfThisSingle(); onSuccess.accept(result); nextOperation(result);- Parameters:
onSuccess- Invoked beforeSingleSource.Subscriber.onSuccess(Object)is called forSingleSource.Subscribers of the returnedSingle. MUST NOT throw.- Returns:
- The new
Single.
-
beforeOnError
public final Single<T> beforeOnError(java.util.function.Consumer<java.lang.Throwable> onError)
Invokes theonErrorConsumerargument beforeSingleSource.Subscriber.onError(Throwable)is called forSingleSource.Subscribers of the returnedSingle.From a sequential programming point of view this method is roughly equivalent to the following:
try { T result = resultOfThisSingle(); } catch (Throwable cause) { onError.accept(cause); nextOperation(cause); }- Parameters:
onError- Invoked beforeSingleSource.Subscriber.onError(Throwable)is called forSingleSource.Subscribers of the returnedSingle. MUST NOT throw.- Returns:
- The new
Single.
-
beforeCancel
public final Single<T> beforeCancel(java.lang.Runnable onCancel)
Invokes theonCancelRunnableargument beforeCancellable.cancel()is called for Subscriptions of the returnedSingle.- Parameters:
onCancel- Invoked beforeCancellable.cancel()is called for Subscriptions of the returnedSingle. MUST NOT throw.- Returns:
- The new
Single.
-
beforeFinally
public final Single<T> beforeFinally(java.lang.Runnable doFinally)
Invokes thewhenFinallyRunnableargument before any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)Cancellable.cancel()
SingleSource.Subscribers of the returnedSingle.From a sequential programming point of view this method is roughly equivalent to the following:
try { T result = resultOfThisSingle(); } finally { doFinally.run(); nextOperation(); // Maybe notifying of cancellation, or termination }- Parameters:
doFinally- Invoked before any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)Cancellable.cancel()
SingleSource.Subscribers of the returnedSingle. MUST NOT throw.- Returns:
- The new
Single. - See Also:
- ReactiveX do operator.
-
beforeFinally
public final Single<T> beforeFinally(TerminalSignalConsumer doFinally)
Invokes the corresponding method onbeforeFinallyTerminalSignalConsumerargument before any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)- invokesTerminalSignalConsumer.onComplete()SingleSource.Subscriber.onError(Throwable)- invokesTerminalSignalConsumer.onError(Throwable)Cancellable.cancel()- invokesTerminalSignalConsumer.cancel()
SingleSource.Subscribers of the returnedSingle.From a sequential programming point of view this method is roughly equivalent to the following:
T result; try { result = resultOfThisSingle(); } catch(Throwable t) { doFinally.onError(t); nextOperation(); // Maybe notifying of cancellation, or termination return; } doFinally.onComplete(); nextOperation(); // Maybe notifying of cancellation, or termination- Parameters:
doFinally- For each subscribe of the returnedSingle, at most one method of thisTerminalSignalConsumerwill be invoked.- Returns:
- The new
Single. - See Also:
- ReactiveX do operator.
-
beforeFinally
public final Single<T> beforeFinally(SingleTerminalSignalConsumer<? super T> doFinally)
Invokes the corresponding method onbeforeFinallySingleTerminalSignalConsumerargument before any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)- invokesSingleTerminalSignalConsumer.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)- invokesSingleTerminalSignalConsumer.onError(Throwable)Cancellable.cancel()- invokesSingleTerminalSignalConsumer.cancel()
SingleSource.Subscribers of the returnedSingle.From a sequential programming point of view this method is roughly equivalent to the following:
T result; try { result = resultOfThisSingle(); } catch(Throwable t) { doFinally.onError(t); nextOperation(); // Maybe notifying of cancellation, or termination return; } doFinally.onSuccess(result); nextOperation(); // Maybe notifying of cancellation, or termination- Parameters:
doFinally- For each subscribe of the returnedSingle, at most one method of thisSingleTerminalSignalConsumerwill be invoked.- Returns:
- The new
Single. - See Also:
- ReactiveX do operator.
-
beforeSubscriber
public final Single<T> beforeSubscriber(java.util.function.Supplier<? extends SingleSource.Subscriber<? super T>> subscriberSupplier)
Creates a newSingleSource.Subscriber(via thesubscriberSupplierargument) on each call to subscribe and invokes all theSingleSource.Subscribermethods before theSingleSource.Subscribers of the returnedSingle.- Parameters:
subscriberSupplier- Creates a newSingleSource.Subscriberon each call to subscribe and invokes all theSingleSource.Subscribermethods before theSingleSource.Subscribers of the returnedSingle.SingleSource.Subscribermethods MUST NOT throw.- Returns:
- The new
Single.
-
afterOnSubscribe
public final Single<T> afterOnSubscribe(java.util.function.Consumer<Cancellable> onSubscribe)
Invokes theonSubscribeConsumerargument afterSingleSource.Subscriber.onSubscribe(Cancellable)is called forSingleSource.Subscribers of the returnedSingle.- Parameters:
onSubscribe- Invoked afterSingleSource.Subscriber.onSubscribe(Cancellable)is called forSingleSource.Subscribers of the returnedSingle. MUST NOT throw.- Returns:
- The new
Single.
-
whenOnSubscribe
public final Single<T> whenOnSubscribe(java.util.function.Consumer<Cancellable> onSubscribe)
Invokes theonSubscribeConsumerargument whenSingleSource.Subscriber.onSubscribe(Cancellable)is called forSingleSource.Subscribers of the returnedSingle.The order in which
onSubscribewill be invoked relative toSingleSource.Subscriber.onSubscribe(Cancellable)is undefined. If you need strict ordering seebeforeOnSubscribe(Consumer)andafterOnSubscribe(Consumer).- Parameters:
onSubscribe- Invoked whenSingleSource.Subscriber.onSubscribe(Cancellable)is called forSingleSource.Subscribers of the returnedSingle. MUST NOT throw.- Returns:
- The new
Single. - See Also:
beforeOnSubscribe(Consumer),afterOnSubscribe(Consumer)
-
afterOnSuccess
public final Single<T> afterOnSuccess(java.util.function.Consumer<? super T> onSuccess)
Invokes theonSuccessConsumerargument afterSingleSource.Subscriber.onSuccess(Object)is called forSingleSource.Subscribers of the returnedSingle.From a sequential programming point of view this method is roughly equivalent to the following:
T result = resultOfThisSingle(); nextOperation(result); onSuccess.accept(result);- Parameters:
onSuccess- Invoked afterSingleSource.Subscriber.onSuccess(Object)is called forSingleSource.Subscribers of the returnedSingle. MUST NOT throw.- Returns:
- The new
Single.
-
afterOnError
public final Single<T> afterOnError(java.util.function.Consumer<java.lang.Throwable> onError)
Invokes theonErrorConsumerargument afterSingleSource.Subscriber.onError(Throwable)is called forSingleSource.Subscribers of the returnedSingle.From a sequential programming point of view this method is roughly equivalent to the following:
try { T result = resultOfThisSingle(); } catch (Throwable cause) { nextOperation(cause); onError.accept(cause); }- Parameters:
onError- Invoked afterSingleSource.Subscriber.onError(Throwable)is called forSingleSource.Subscribers of the returnedSingle. MUST NOT throw.- Returns:
- The new
Single.
-
afterCancel
public final Single<T> afterCancel(java.lang.Runnable onCancel)
Invokes theonCancelRunnableargument afterCancellable.cancel()is called for Subscriptions of the returnedSingle.- Parameters:
onCancel- Invoked afterCancellable.cancel()is called for Subscriptions of the returnedSingle. MUST NOT throw.- Returns:
- The new
Single.
-
afterFinally
public final Single<T> afterFinally(java.lang.Runnable doFinally)
Invokes thewhenFinallyRunnableargument after any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)Cancellable.cancel()
SingleSource.Subscribers of the returnedSingle.From a sequential programming point of view this method is roughly equivalent to the following:
try { T result = resultOfThisSingle(); } finally { nextOperation(); // Maybe notifying of cancellation, or termination doFinally.run(); }- Parameters:
doFinally- Invoked after any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)Cancellable.cancel()
SingleSource.Subscribers of the returnedSingle. MUST NOT throw.- Returns:
- The new
Single. - See Also:
- ReactiveX do operator.
-
afterFinally
public final Single<T> afterFinally(TerminalSignalConsumer doFinally)
Invokes the corresponding method onafterFinallyTerminalSignalConsumerargument after any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)- invokesTerminalSignalConsumer.onComplete()SingleSource.Subscriber.onError(Throwable)- invokesTerminalSignalConsumer.onError(Throwable)Cancellable.cancel()- invokesTerminalSignalConsumer.cancel()
SingleSource.Subscribers of the returnedSingle.From a sequential programming point of view this method is roughly equivalent to the following:
T result; try { result = resultOfThisSingle(); } catch(Throwable t) { nextOperation(); // Maybe notifying of cancellation, or termination doFinally.onError(t); return; } nextOperation(); // Maybe notifying of cancellation, or termination doFinally.onComplete();- Parameters:
doFinally- For each subscribe of the returnedSingle, at most one method of thisTerminalSignalConsumerwill be invoked.- Returns:
- The new
Single. - See Also:
- ReactiveX do operator.
-
afterFinally
public final Single<T> afterFinally(SingleTerminalSignalConsumer<? super T> doFinally)
Invokes the corresponding method onafterFinallySingleTerminalSignalConsumerargument after any of the following terminal methods are called:SingleSource.Subscriber.onSuccess(Object)- invokesSingleTerminalSignalConsumer.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)- invokesSingleTerminalSignalConsumer.onError(Throwable)Cancellable.cancel()- invokesSingleTerminalSignalConsumer.cancel()
SingleSource.Subscribers of the returnedSingle.From a sequential programming point of view this method is roughly equivalent to the following:
T result; try { result = resultOfThisSingle(); } catch(Throwable t) { nextOperation(); // Maybe notifying of cancellation, or termination doFinally.onError(t); return; } nextOperation(); // Maybe notifying of cancellation, or termination doFinally.onSuccess(result);- Parameters:
doFinally- For each subscribe of the returnedSingle, at most one method of thisSingleTerminalSignalConsumerwill be invoked.- Returns:
- The new
Single. - See Also:
- ReactiveX do operator.
-
afterSubscriber
public final Single<T> afterSubscriber(java.util.function.Supplier<? extends SingleSource.Subscriber<? super T>> subscriberSupplier)
Creates a newSingleSource.Subscriber(via thesubscriberSupplierargument) on each call to subscribe and invokes all theSingleSource.Subscribermethods after theSingleSource.Subscribers of the returnedSingle.- Parameters:
subscriberSupplier- Creates a newSingleSource.Subscriberon each call to subscribe and invokes all theSingleSource.Subscribermethods after theSingleSource.Subscribers of the returnedSingle.SingleSource.Subscribermethods MUST NOT throw.- Returns:
- The new
Single.
-
whenSubscriber
public final Single<T> whenSubscriber(java.util.function.Supplier<? extends SingleSource.Subscriber<? super T>> subscriberSupplier)
Creates a newSingleSource.Subscriber(via thesubscriberSupplierargument) for each new subscribe and invokes methods on thatSingleSource.Subscriberwhen the corresponding methods are called forSingleSource.Subscribers of the returnedSingle.- Parameters:
subscriberSupplier- Creates a newSingleSource.Subscriberfor each new subscribe and invokes methods on thatSingleSource.Subscriberwhen the corresponding methods are called forSingleSource.Subscribers of the returnedSingle.SingleSource.Subscribermethods MUST NOT throw.- Returns:
- The new
Single.
-
publishOn
public final Single<T> publishOn(Executor executor)
Creates a newSinglethat will use the passedExecutorto invoke allSingleSource.Subscribermethods. This method does not override precedingExecutors, if any, specified forthisSingle. Only subsequent operations, if any, added in this execution chain will use thisExecutor. If such an override is required,publishOnOverride(Executor)can be used.- Parameters:
executor-Executorto use.- Returns:
- A new
Singlethat will use the passedExecutorto invoke all methods on theSingleSource.Subscriber.
-
publishOnOverride
public final Single<T> publishOnOverride(Executor executor)
Creates a newSinglethat will use the passedExecutorto invoke allSingleSource.Subscribermethods. This method overrides precedingExecutors, if any, specified forthisSingle. That is to say preceding and subsequent operations for this execution chain will use thisExecutorfor invoking allSingleSource.Subscribermethods. If such an override is not required,publishOn(Executor)can be used.- Parameters:
executor-Executorto use.- Returns:
- A new
Singlethat will use the passedExecutorto invoke all methods ofSingleSource.Subscriber,CancellableandhandleSubscribe(SingleSource.Subscriber)both for the returnedSingleas well asthisSingle.
-
subscribeOn
public final Single<T> subscribeOn(Executor executor)
Creates a newSinglethat will use the passedExecutorto invoke the following methods:- All
Cancellablemethods. - The
handleSubscribe(SingleSource.Subscriber)method.
Executors, if any, specified forthisSingle. Only subsequent operations, if any, added in this execution chain will use thisExecutor. If such an override is required,subscribeOnOverride(Executor)can be used.- Parameters:
executor-Executorto use.- Returns:
- A new
Singlethat will use the passedExecutorto invoke all methods ofCancellableandhandleSubscribe(SingleSource.Subscriber).
- All
-
subscribeOnOverride
public final Single<T> subscribeOnOverride(Executor executor)
Creates a newSinglethat will use the passedExecutorto invoke the following methods:- All
Cancellablemethods. - The
handleSubscribe(SingleSource.Subscriber)method.
Executors, if any, specified forthisSingle. That is to say preceding and subsequent operations for this execution chain will use thisExecutorfor invoking the above specified methods. If such an override is not required,subscribeOn(Executor)can be used.- Parameters:
executor-Executorto use.- Returns:
- A new
Singlethat will use the passedExecutorto invoke all methods ofCancellableandhandleSubscribe(SingleSource.Subscriber)both for the returnedSingleas well asthisSingle.
- All
-
publishAndSubscribeOn
public final Single<T> publishAndSubscribeOn(Executor executor)
Creates a newSinglethat will use the passedExecutorto invoke the following methods:- All
SingleSource.Subscribermethods. - All
Cancellablemethods. - The
handleSubscribe(SingleSource.Subscriber)method.
Executors, if any, specified forthisSingle. Only subsequent operations, if any, added in this execution chain will use thisExecutor. If such an override is required,publishAndSubscribeOnOverride(Executor)can be used.- Parameters:
executor-Executorto use.- Returns:
- A new
Singlethat will use the passedExecutorto invoke all methodsSingleSource.Subscriber,CancellableandhandleSubscribe(SingleSource.Subscriber).
- All
-
publishAndSubscribeOnOverride
public final Single<T> publishAndSubscribeOnOverride(Executor executor)
Creates a newSinglethat will use the passedExecutorto invoke the following methods:- All
SingleSource.Subscribermethods. - All
Cancellablemethods. - The
handleSubscribe(SingleSource.Subscriber)method.
Executors, if any, specified forthisSingle. That is to say preceding and subsequent operations for this execution chain will use thisExecutor. If such an override is not required,publishAndSubscribeOn(Executor)can be used.- Parameters:
executor-Executorto use.- Returns:
- A new
Singlethat will use the passedExecutorto invoke all methods ofSingleSource.Subscriber,CancellableandhandleSubscribe(SingleSource.Subscriber)both for the returnedSingleas well asthisSingle.
- All
-
subscribeShareContext
public final Single<T> subscribeShareContext()
Signifies that when the returnedSingleis subscribed to, theAsyncContextwill be shared instead of making acopy.This operator only impacts behavior if the returned
Singleis subscribed directly after this operator, that means this must be the "last operator" in the chain for this to have an impact.- Returns:
- A
Singlethat will share theAsyncContextinstead of making acopywhen subscribed to.
-
liftSync
public final <R> Single<R> liftSync(SingleOperator<? super T,? extends R> operator)
This method requires advanced knowledge of building operators. Before using this method please attempt to compose existing operator(s) to satisfy your use case.Returns a
Singlewhich will wrap theSingleSource.Subscriberusing the providedoperatorargument before subscribing to thisSingle.
TheSingle<X> pub = ...; pub.map(..) // A .liftSync(original -> modified) .afterFinally(..) // Boriginal -> modified"operator" MUST be "synchronous" in that it does not interact with the originalSingleSource.Subscriberfrom outside the modifiedSingleSource.SubscriberorCancellablethreads. That is to say this operator will not impact theExecutorconstraints already in place between A and B above. If you need asynchronous behavior, or are unsure, seeliftAsync(SingleOperator).- Type Parameters:
R- Type of the items emitted by the returnedSingle.- Parameters:
operator- The custom operator logic. The input is the "original"SingleSource.Subscriberto thisSingleand the return is the "modified"SingleSource.Subscriberthat provides custom operator business logic.- Returns:
- a
Singlewhich when subscribed, theoperatorargument will be used to wrap theSingleSource.Subscriberbefore subscribing to thisSingle. - See Also:
liftAsync(SingleOperator)
-
liftAsync
public final <R> Single<R> liftAsync(SingleOperator<? super T,? extends R> operator)
This method requires advanced knowledge of building operators. Before using this method please attempt to compose existing operator(s) to satisfy your use case.Returns a
Singlewhich will wrap theSingleSource.Subscriberusing the providedoperatorargument before subscribing to thisSingle.
ThePublisher<X> pub = ...; pub.map(..) // Aw .liftAsync(original -> modified) .afterFinally(..) // Boriginal -> modified"operator" MAY be "asynchronous" in that it may interact with the originalSingleSource.Subscriberfrom outside the modifiedSingleSource.SubscriberorCancellablethreads. More specifically:- all of the
SingleSource.Subscriberinvocations going "downstream" (i.e. from A to B above) MAY be offloaded via anExecutor - all of the
Cancellableinvocations going "upstream" (i.e. from B to A above) MAY be offloaded via anExecutor
- Type Parameters:
R- Type of the items emitted by the returnedSingle.- Parameters:
operator- The custom operator logic. The input is the "original"SingleSource.Subscriberto thisSingleand the return is the "modified"SingleSource.Subscriberthat provides custom operator business logic.- Returns:
- a
Singlewhich when subscribed, theoperatorargument will be used to wrap theSingleSource.Subscriberbefore subscribing to thisSingle. - See Also:
liftSync(SingleOperator)
- all of the
-
ambWith
public final Single<T> ambWith(Single<T> other)
Creates a newSinglethat terminates with the result (either success or error) of either thisSingleor the passedotherSingle, whichever terminates first.From a sequential programming point of view this method is roughly equivalent to the following:
for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here) // This is an approximation, this operator will pick the first result from either of the futures. return ft.get(); }
-
toPublisher
public final Publisher<T> toPublisher()
Converts thisSingleto aPublisher.- Returns:
- A
Publisherthat emits at most a single item which is emitted by thisSingle.
-
toCompletable
public final Completable toCompletable()
Ignores the result of thisSingleand forwards the termination signal to the returnedCompletable.- Returns:
- A
Completablethat mirrors the terminal signal from thisSingle.
-
ignoreElement
public final Completable ignoreElement()
Ignores the result of thisSingleand forwards the termination signal to the returnedCompletable.- Returns:
- A
Completablethat mirrors the terminal signal from thisSingle.
-
toCompletionStage
public final java.util.concurrent.CompletionStage<T> toCompletionStage()
Convert thisSingleto aCompletionStage.- Returns:
- A
CompletionStagethat mirrors the terminal signal from thisSingle.
-
toFuture
public final java.util.concurrent.Future<T> toFuture()
Convert thisSingleto aFuture.- Returns:
- A
Futurethat mirrors the terminal signal from thisSingle.
-
subscribeInternal
protected final void subscribeInternal(SingleSource.Subscriber<? super T> subscriber)
A internal subscribe method similar toSingleSource.subscribe(Subscriber)which can be used by different implementations to subscribe.- Parameters:
subscriber-SingleSource.Subscriberto subscribe for the result.
-
subscribe
public final Cancellable subscribe(java.util.function.Consumer<? super T> resultConsumer)
Subscribe to thisSingle, emits the result to the passedConsumerand log anySingleSource.Subscriber.onError(Throwable).- Parameters:
resultConsumer-Consumerto accept the result of thisSingle.- Returns:
Cancellableused to invokeCancellable.cancel()on the parameter ofSingleSource.Subscriber.onSubscribe(Cancellable)for thisSingle.
-
handleSubscribe
protected abstract void handleSubscribe(SingleSource.Subscriber<? super T> subscriber)
Handles a subscriber to thisSingle.- Parameters:
subscriber- the subscriber.
-
succeeded
public static <T> Single<T> succeeded(@Nullable T value)
Creates a realizedSinglewhich always completes successfully with the providedvalue.
-
fromCallable
public static <T> Single<T> fromCallable(java.util.concurrent.Callable<T> callable)
Creates aSinglewhich when subscribed will invokeCallable.call()on the passedCallableand emit the value returned by that invocation from the returnedSingle. Any error emitted by theCallablewill terminate the returnedSinglewith the same error.Blocking inside
Callable.call()will in turn block the subscribe call to the returnedSingle. If this behavior is undesirable then the returnedSingleshould be offloaded using one of the operators that offloads the subscribe call (eg:subscribeOn(Executor),publishAndSubscribeOn(Executor)).
-
fromSupplier
public static <T> Single<T> fromSupplier(java.util.function.Supplier<T> supplier)
Creates aSinglewhich when subscribed will invokeSupplier.get()on the passedSupplierand emit the value returned by that invocation from the returnedSingle. Any error emitted by theSupplierwill terminate the returnedSinglewith the same error.Blocking inside
Supplier.get()will in turn block the subscribe call to the returnedSingle. If this behavior is undesirable then the returnedSingleshould be offloaded using one of the operators that offloads the subscribe call (eg:subscribeOn(Executor),publishAndSubscribeOn(Executor)).
-
failed
public static <T> Single<T> failed(java.lang.Throwable cause)
Creates a realizedSinglewhich always completes with the provided errorcause.
-
defer
public static <T> Single<T> defer(java.util.function.Supplier<? extends Single<? extends T>> singleSupplier)
Defer creation of aSingletill it is subscribed to.- Type Parameters:
T- Type of theSingle.- Parameters:
singleSupplier-Supplierto create a newSingleevery time the returnedSingleis subscribed.- Returns:
- A new
Singlethat creates a newSingleusingsingleSupplierevery time it is subscribed and forwards all items and terminal events from the newly createdSingleto itsSingleSource.Subscriber.
-
fromFuture
public static <T> Single<T> fromFuture(java.util.concurrent.Future<? extends T> future)
Convert from aFutureto aSingleviaFuture.get().Note that because
Futureonly presents blocking APIs to extract the result, so the process of getting the results will block. The caller of subscribe is responsible for offloading if necessary, and also offloading ifCancellable.cancel()will be called and this operation may block.To apply a timeout see
timeout(long, TimeUnit)and related methods.- Type Parameters:
T- The data type theFutureprovides when complete.- Parameters:
future- TheFutureto convert.- Returns:
- A
Singlethat derives results fromFuture. - See Also:
timeout(long, TimeUnit)
-
collectUnordered
public static <T> Single<java.util.Collection<T>> collectUnordered(java.lang.Iterable<? extends Single<? extends T>> singles)
Asynchronously collects results of individualSingles returned by the passedIterableinto a singleCollection.This will actively subscribe to a limited number of
Singles concurrently, in order to alter the defaults,collectUnordered(Iterable, int)should be used.If any of the
Singles terminate with an error, returnedSinglewill immediately terminate with that error. In such a case, any in progressSingles will be cancelled. In order to delay error termination usecollectUnorderedDelayError(Iterable).From a sequential programming point of view this method is roughly equivalent to the following:
List<T> result = ...;// assume this is thread safe for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here) // This is an approximation, this operator does not provide any ordering guarantees for the results. result.add(ft.get()); } return result;- Type Parameters:
T- Type of the result of the individualSingles- Parameters:
singles-IterableofSingles, results of which are to be collected.- Returns:
- A
Singleproducing aCollectionof all values produced by the individualSingles. There is no guarantee of the order of the values in the producedCollectionas compared to the order ofSingles passed to this method.
-
collectUnordered
@SafeVarargs public static <T> Single<java.util.Collection<T>> collectUnordered(Single<? extends T>... singles)
Asynchronously collects results of the passedSingles into a singleCollection.This will actively subscribe to a limited number of
Singles concurrently, in order to alter the defaults,collectUnordered(int, Single[])should be used.If any of the
Singles terminate with an error, returnedSinglewill immediately terminate with that error. In such a case, any in progressSingles will be cancelled. In order to delay error termination usecollectUnorderedDelayError(Single[]).From a sequential programming point of view this method is roughly equivalent to the following:
List<T> result = ...;// assume this is thread safe for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here) // This is an approximation, this operator does not provide any ordering guarantees for the results. result.add(ft.get()); } return result;- Type Parameters:
T- Type of the result of the individualSingles- Parameters:
singles-Singles, results of which are to be collected.- Returns:
- A
Singleproducing aCollectionof all values produced by the individualSingles. There is no guarantee of the order of the values in the producedCollectionas compared to the order ofSingles passed to this method.
-
collectUnordered
public static <T> Single<java.util.Collection<T>> collectUnordered(java.lang.Iterable<? extends Single<? extends T>> singles, int maxConcurrency)
Asynchronously collects results of individualSingles returned by the passedIterableinto a singleCollection.If any of the
Singles terminate with an error, returnedSinglewill immediately terminate with that error. In such a case, any in progressSingles will be cancelled. In order to delay error termination usecollectUnorderedDelayError(Iterable, int).From a sequential programming point of view this method is roughly equivalent to the following:
List<T> result = ...;// assume this is thread safe for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here) // This is an approximation, this operator does not provide any ordering guarantees for the results. result.add(ft.get()); } return result;- Type Parameters:
T- Type of the result of the individualSingles- Parameters:
singles-IterableofSingles, results of which are to be collected.maxConcurrency- Maximum number ofSingles that will be active at any point in time.- Returns:
- A
Singleproducing aCollectionof all values produced by the individualSingles. There is no guarantee of the order of the values in the producedCollectionas compared to the order ofSingles passed to this method.
-
collectUnordered
@SafeVarargs public static <T> Single<java.util.Collection<T>> collectUnordered(int maxConcurrency, Single<? extends T>... singles)
Asynchronously collects results of the passedSingles into a singleCollection.If any of the
Singles terminate with an error, returnedSinglewill immediately terminate with that error. In such a case, any in progressSingles will be cancelled. In order to delay error termination usecollectUnorderedDelayError(int, Single[]).From a sequential programming point of view this method is roughly equivalent to the following:
List<T> result = ...;// assume this is thread safe for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here) // This is an approximation, this operator does not provide any ordering guarantees for the results. result.add(ft.get()); } return result;- Type Parameters:
T- Type of the result of the individualSingles- Parameters:
maxConcurrency- Maximum number ofSingles that will be active at any point in time.singles-Singles, results of which are to be collected.- Returns:
- A
Singleproducing aCollectionof all values produced by the individualSingles. There is no guarantee of the order of the values in the producedCollectionas compared to the order ofSingles passed to this method.
-
collectUnorderedDelayError
public static <T> Single<java.util.Collection<T>> collectUnorderedDelayError(java.lang.Iterable<? extends Single<? extends T>> singles)
Asynchronously collects results of individualSingles returned by the passedIterableinto a singleCollection.This will actively subscribe to a limited number of
Singles concurrently, in order to alter the defaults,collectUnorderedDelayError(Iterable, int).If any of the
Singles terminate with an error, returnedSinglewill wait for termination till all the otherSingles have been subscribed and terminated. If it is expected for the returnedSingleto terminate on the first failingSingle,collectUnordered(Iterable)should be used.From a sequential programming point of view this method is roughly equivalent to the following:
List<T> result = ...;// assume this is thread safe List<Throwable> errors = ...; // assume this is thread safe for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here) // This is an approximation, this operator does not provide any ordering guarantees for the results. try { result.add(ft.get()); } catch(Throwable t) { errors.add(t); } } if (errors.isEmpty()) { return rResults; } createAndThrowACompositeException(errors);- Type Parameters:
T- Type of the result of the individualSingles- Parameters:
singles-IterableofSingles, results of which are to be collected.- Returns:
- A
Singleproducing aCollectionof all values produced by the individualSingles. There is no guarantee of the order of the values in the producedCollectionas compared to the order ofSingles passed to this method.
-
collectUnorderedDelayError
@SafeVarargs public static <T> Single<java.util.Collection<T>> collectUnorderedDelayError(Single<? extends T>... singles)
Asynchronously collects results of the passedSingles into a singleCollection.This will actively subscribe to a limited number of
Singles concurrently, in order to alter the defaults,collectUnordered(int, Single[]).If any of the
Singles terminate with an error, returnedSinglewill wait for termination till all the otherSingles have been subscribed and terminated. If it is expected for the returnedSingleto terminate on the first failingSingle,collectUnordered(Single[])should be used.From a sequential programming point of view this method is roughly equivalent to the following:
List<T> result = ...;// assume this is thread safe List<Throwable> errors = ...; // assume this is thread safe for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here) // This is an approximation, this operator does not provide any ordering guarantees for the results. try { result.add(ft.get()); } catch(Throwable t) { errors.add(t); } } if (errors.isEmpty()) { return rResults; } createAndThrowACompositeException(errors);- Type Parameters:
T- Type of the result of the individualSingles- Parameters:
singles-Singles, results of which are to be collected.- Returns:
- A
Singleproducing aCollectionof all values produced by the individualSingles. There is no guarantee of the order of the values in the producedCollectionas compared to the order ofSingles passed to this method.
-
collectUnorderedDelayError
public static <T> Single<java.util.Collection<T>> collectUnorderedDelayError(java.lang.Iterable<? extends Single<? extends T>> singles, int maxConcurrency)
Asynchronously collects results of individualSingles returned by the passedIterableinto a singleCollection.If any of the
Singles terminate with an error, returnedSinglewill wait for termination till all the otherSingles have been subscribed and terminated. If it is expected for the returnedSingleto terminate on the first failingSingle,collectUnordered(Iterable, int)should be used.From a sequential programming point of view this method is roughly equivalent to the following:
List<T> result = ...;// assume this is thread safe List<Throwable> errors = ...; // assume this is thread safe for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here) // This is an approximation, this operator does not provide any ordering guarantees for the results. try { result.add(ft.get()); } catch(Throwable t) { errors.add(t); } } if (errors.isEmpty()) { return rResults; } createAndThrowACompositeException(errors);- Type Parameters:
T- Type of the result of the individualSingles- Parameters:
singles-IterableofSingles, results of which are to be collected.maxConcurrency- Maximum number ofSingles that will be active at any point in time.- Returns:
- A
Singleproducing aCollectionof all values produced by the individualSingles. There is no guarantee of the order of the values in the producedCollectionas compared to the order ofSingles passed to this method.
-
collectUnorderedDelayError
@SafeVarargs public static <T> Single<java.util.Collection<T>> collectUnorderedDelayError(int maxConcurrency, Single<? extends T>... singles)
Asynchronously collects results of the passedSingles into a singleCollection.If any of the
Singles terminate with an error, returnedSinglewill wait for termination till all the otherSingles have been subscribed and terminated. If it is expected for the returnedSingleto terminate on the first failingSingle,collectUnordered(Iterable, int)should be used.From a sequential programming point of view this method is roughly equivalent to the following:
List<T> result = ...;// assume this is thread safe List<Throwable> errors = ...; // assume this is thread safe for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here) // This is an approximation, this operator does not provide any ordering guarantees for the results. try { result.add(ft.get()); } catch(Throwable t) { errors.add(t); } } if (errors.isEmpty()) { return rResults; } createAndThrowACompositeException(errors);- Type Parameters:
T- Type of the result of the individualSingles- Parameters:
maxConcurrency- Maximum number ofSingles that will be active at any point in time.singles-Singles, results of which are to be collected.- Returns:
- A
Singleproducing aCollectionof all values produced by the individualSingles. There is no guarantee of the order of the values in the producedCollectionas compared to the order ofSingles passed to this method.
-
fromStage
public static <T> Single<T> fromStage(java.util.concurrent.CompletionStage<? extends T> stage)
Convert from aCompletionStageto aSingle.A best effort is made to propagate
Cancellable.cancel()to theCompletionStage. Cancellation forCompletionStageimplementations will result in exceptional completion and invoke user callbacks. If there is any blocking code involved in the cancellation process (including invoking user callbacks) you should investigate if using anExecutoris appropriate.- Type Parameters:
T- The data type theCompletionStageprovides when complete.- Parameters:
stage- TheCompletionStageto convert.- Returns:
- A
Singlethat derives results fromCompletionStage.
-
amb
@SafeVarargs public static <T> Single<T> amb(Single<? extends T>... singles)
Creates a newSinglethat terminates with the result (either success or error) of whichever amongst the passedsinglesthat terminates first.From a sequential programming point of view this method is roughly equivalent to the following:
for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here) // This is an approximation, this operator will pick the first result from any of the futures. return ft.get(); }- Type Parameters:
T- Type of the result of the individualSingles- Parameters:
singles-Singles the result of which are to be ambiguated.- Returns:
- A new
Singlethat terminates with the result (either success or error) of whichever amongst the passedsinglesthat terminates first. - See Also:
- ReactiveX amb operator.
-
amb
public static <T> Single<T> amb(java.lang.Iterable<Single<? extends T>> singles)
Creates a newSinglethat terminates with the result (either success or error) of whichever amongst the passedsinglesthat terminates first.From a sequential programming point of view this method is roughly equivalent to the following:
for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here) // This is an approximation, this operator will pick the first result from any of the futures. return ft.get(); }- Type Parameters:
T- Type of the result of the individualSingles- Parameters:
singles-Singles the result of which are to be ambiguated.- Returns:
- A new
Singlethat terminates with the result (either success or error) of whichever amongst the passedsinglesthat terminates first. - See Also:
- ReactiveX amb operator.
-
anyOf
@SafeVarargs public static <T> Single<T> anyOf(Single<? extends T>... singles)
Creates a newSinglethat terminates with the result (either success or error) of whichever amongst the passedsinglesthat terminates first.From a sequential programming point of view this method is roughly equivalent to the following:
for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here) // This is an approximation, this operator will pick the first result from any of the futures. return ft.get(); }- Type Parameters:
T- Type of the result of the individualSingles- Parameters:
singles-Singles the result of which are to be ambiguated.- Returns:
- A new
Singlethat terminates with the result (either success or error) of whichever amongst the passedsinglesthat terminates first. - See Also:
- ReactiveX amb operator.
-
anyOf
public static <T> Single<T> anyOf(java.lang.Iterable<Single<? extends T>> singles)
Creates a newSinglethat terminates with the result (either success or error) of whichever amongst the passedsinglesthat terminates first.From a sequential programming point of view this method is roughly equivalent to the following:
for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here) // This is an approximation, this operator will pick the first result from any of the futures. return ft.get(); }- Type Parameters:
T- Type of the result of the individualSingles- Parameters:
singles-Singles the result of which are to be ambiguated.- Returns:
- A new
Singlethat terminates with the result (either success or error) of whichever amongst the passedsinglesthat terminates first. - See Also:
- ReactiveX amb operator.
-
zip
public static <T1,T2,R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, java.util.function.BiFunction<? super T1,? super T2,? extends R> zipper)
Create a newSinglethat emits the results of a specified zipperBiFunctionto items emitted bysingles.From a sequential programming point of view this method is roughly equivalent to the following:
CompletableFuture<T1> f1 = ...; // s1 CompletableFuture<T2> f2 = ...; // s2 CompletableFuture.allOf(f1, f2).get(); // wait for all futures to complete return zipper.apply(f1.get(), f2.get());- Type Parameters:
T1- The type for the firstSingle.T2- The type for the secondSingle.R- The result type of the zipper.- Parameters:
s1- The firstSingleto zip.s2- The secondSingleto zip.zipper- Used to combine the completed results for each item fromsingles.- Returns:
- a new
Singlethat emits the results of a specified zipperBiFunctionto items emitted bysingles. - See Also:
- ReactiveX zip operator.
-
zip
public static <T1,T2,T3,R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Function3<? super T1,? super T2,? super T3,? extends R> zipper)
Create a newSinglethat emits the results of a specified zipperFunction3to items emitted bysingles.From a sequential programming point of view this method is roughly equivalent to the following:
CompletableFuture<T1> f1 = ...; // s1 CompletableFuture<T2> f2 = ...; // s2 CompletableFuture<T3> f3 = ...; // s3 CompletableFuture.allOf(f1, f2, f3).get(); // wait for all futures to complete return zipper.apply(f1.get(), f2.get(), f3.get());- Type Parameters:
T1- The type for the firstSingle.T2- The type for the secondSingle.T3- The type for the thirdSingle.R- The result type of the zipper.- Parameters:
s1- The firstSingleto zip.s2- The secondSingleto zip.s3- The thirdSingleto zip.zipper- Used to combine the completed results for each item fromsingles.- Returns:
- a new
Singlethat emits the results of a specified zipperFunction3to items emitted bysingles. - See Also:
- ReactiveX zip operator.
-
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, Function4<? super T1,? super T2,? super T3,? super T4,? extends R> zipper)
Create a newSinglethat emits the results of a specified zipperFunction4to items emitted bysingles.From a sequential programming point of view this method is roughly equivalent to the following:
CompletableFuture<T1> f1 = ...; // s1 CompletableFuture<T2> f2 = ...; // s2 CompletableFuture<T3> f3 = ...; // s3 CompletableFuture<T4> f4 = ...; // s3 CompletableFuture.allOf(f1, f2, f3, f4).get(); // wait for all futures to complete return zipper.apply(f1.get(), f2.get(), f3.get(), f4.get());- Type Parameters:
T1- The type for the firstSingle.T2- The type for the secondSingle.T3- The type for the thirdSingle.T4- The type for the fourthSingle.R- The result type of the zipper.- Parameters:
s1- The firstSingleto zip.s2- The secondSingleto zip.s3- The thirdSingleto zip.s4- The fourthSingleto zip.zipper- Used to combine the completed results for each item fromsingles.- Returns:
- a new
Singlethat emits the results of a specified zipperFunction4to items emitted bysingles. - See Also:
- ReactiveX zip operator.
-
zip
public static <R> Single<R> zip(java.util.function.Function<? super java.lang.Object[],? extends R> zipper, Single<?>... singles)
Create a newSinglethat emits the results of a specified zipperFunctionto items emitted bysingles.From a sequential programming point of view this method is roughly equivalent to the following:
Function<? super CompletableFuture<?>[], ? extends R> zipper = ...; CompletableFuture<?>[] futures = ...; // Provided Futures (analogous to the Singles here) CompletableFuture.allOf(futures).get(); // wait for all futures to complete return zipper.apply(futures);- Type Parameters:
R- The result type of the zipper.- Parameters:
zipper- Used to combine the completed results for each item fromsingles.singles- The collection ofSingles that when complete provides the results to "zip" (aka combine) together.- Returns:
- a new
Singlethat emits the results of a specified zipperFunctionto items emitted bysingles. - See Also:
- ReactiveX zip operator.
-
-