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:
SubscribableSingle

public abstract class Single<T> extends Object
An 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 a SingleSource.Subscriber as 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 a source adapter can be used to convert to a SingleSource.
  • Constructor Details

    • Single

      protected Single()
      New instance.
  • Method Details

    • map

      public final <R> Single<R> map(Function<? super T,? extends R> mapper)
      Maps the result of this single to a different type. Error, if any is forwarded to the returned Single.

      This method provides a data transformation in sequential programming similar to:

      
           T tResult = resultOfThisSingle();
           R rResult = mapper.apply(tResult);
       
      Type Parameters:
      R - Type of the returned Single.
      Parameters:
      mapper - To convert this result to other.
      Returns:
      A new Single that will now have the result of type Single.
    • cast

      public final <R> Single<R> cast(Class<R> clazz)
      Cast this Single from type Single to type Single.

      This method provides a data transformation in sequential programming similar to:

      
           T tResult = resultOfThisSingle();
           R rResult = clazz.cast(tResult);
       
      Type Parameters:
      R - The resulting type of the cast operation.
      Parameters:
      clazz - The type to cast to.
      Returns:
      The cast of this Single to type Single. Terminates with a ClassCastException if signals cannot be cast to type Single.
      See Also:
    • onErrorReturn

      public final Single<T> onErrorReturn(Function<? super Throwable,? extends T> itemSupplier)
      Transform errors emitted on this Single into SingleSource.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 to SingleSource.Subscriber.onSuccess(Object).
      Returns:
      A Single which transform errors emitted on this Single into SingleSource.Subscriber.onSuccess(Object) signal (e.g. swallows the error).
      See Also:
    • onErrorReturn

      public final <E extends Throwable> Single<T> onErrorReturn(Class<E> type, Function<? super E,? extends T> itemSupplier)
      Transform errors emitted on this Single which match type into SingleSource.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 of Throwable to transform.
      Parameters:
      type - The Throwable type to filter, operator will not apply for errors which don't match this type.
      itemSupplier - returns the element to emit to SingleSource.Subscriber.onSuccess(Object).
      Returns:
      A Single which transform errors emitted on this Single into SingleSource.Subscriber.onSuccess(Object) signal (e.g. swallows the error).
      See Also:
    • onErrorReturn

      public final Single<T> onErrorReturn(Predicate<? super Throwable> predicate, Function<? super Throwable,? extends T> itemSupplier)
      Transform errors emitted on this Single which match predicate into SingleSource.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 - returns true if the Throwable should be transformed to SingleSource.Subscriber.onSuccess(Object) signal. Returns false to propagate the error.
      itemSupplier - returns the element to emit to SingleSource.Subscriber.onSuccess(Object).
      Returns:
      A Single which transform errors emitted on this Single into SingleSource.Subscriber.onSuccess(Object) signal (e.g. swallows the error).
      See Also:
    • onErrorMap

      public final Single<T> onErrorMap(Function<? super Throwable,? extends Throwable> mapper)
      Transform errors emitted on this Single into 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 returned Single.
      Returns:
      A Single which transform errors emitted on this Single into a different error.
      See Also:
    • onErrorMap

      public final <E extends Throwable> Single<T> onErrorMap(Class<E> type, Function<? super E,? extends Throwable> mapper)
      Transform errors emitted on this Single which match type into 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 of Throwable to transform.
      Parameters:
      type - The Throwable type to filter, operator will not apply for errors which don't match this type.
      mapper - returns the error used to terminate the returned Single.
      Returns:
      A Single which transform errors emitted on this Single into a different error.
      See Also:
    • onErrorMap

      public final Single<T> onErrorMap(Predicate<? super Throwable> predicate, Function<? super Throwable,? extends Throwable> mapper)
      Transform errors emitted on this Single which match predicate into 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 - returns true if the Throwable should be transformed via mapper. Returns false to propagate the original error.
      mapper - returns the error used to terminate the returned Single.
      Returns:
      A Single which transform errors emitted on this Single into a different error.
      See Also:
    • onErrorResume

      public final Single<T> onErrorResume(Function<? super Throwable,? extends Single<? extends T>> nextFactory)
      Recover from any error emitted by this Single by using another Single provided by the passed nextFactory.

      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;
       
      Parameters:
      nextFactory - Returns the next Single, when this Single emits an error.
      Returns:
      A Single that recovers from an error from this Single by using another Single provided by the passed nextFactory.
    • onErrorResume

      public final <E extends Throwable> Single<T> onErrorResume(Class<E> type, Function<? super E,? extends Single<? extends T>> nextFactory)
      Recover from errors emitted by this Single which match type by using another Single provided by the passed nextFactory.

      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 of Throwable to transform.
      Parameters:
      type - The Throwable type to filter, operator will not apply for errors which don't match this type.
      nextFactory - Returns the next Single, when this Single emits an error.
      Returns:
      A Single that recovers from an error from this Single by using another Single provided by the passed nextFactory.
      See Also:
    • onErrorResume

      public final Single<T> onErrorResume(Predicate<? super Throwable> predicate, Function<? super Throwable,? extends Single<? extends T>> nextFactory)
      Recover from errors emitted by this Single which match predicate by using another Single provided by the passed nextFactory.

      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 - returns true if the Throwable should be transformed via nextFactory. Returns false to propagate the original error.
      nextFactory - Returns the next Single, when this Single emits an error.
      Returns:
      A Single that recovers from an error from this Single by using another Single provided by the passed nextFactory.
      See Also:
    • flatMap

      public final <R> Single<R> flatMap(Function<? super T,? extends Single<? extends R>> next)
      Returns a Single that mirrors emissions from the Single returned by next. Any error emitted by this Single is forwarded to the returned Single.

      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.
       
      Type Parameters:
      R - Type of the result of the resulting Single.
      Parameters:
      next - Function to give the next Single.
      Returns:
      New Single that switches to the Single returned by next after this Single completes successfully.
    • flatMapCompletable

      public final Completable flatMapCompletable(Function<? super T,? extends Completable> next)
      Returns a Completable that mirrors emissions from the Completable returned by next. Any error emitted by this Single is forwarded to the returned Completable.

      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 next Completable.
      Returns:
      New Completable that switches to the Completable returned by next after this Single completes successfully.
    • flatMapPublisher

      public final <R> Publisher<R> flatMapPublisher(Function<? super T,? extends Publisher<? extends R>> next)
      Returns a Publisher that mirrors emissions from the Publisher returned by next. Any error emitted by this Single is forwarded to the returned Publisher.

      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
           }
       
      Type Parameters:
      R - Type of objects emitted by the returned Publisher.
      Parameters:
      next - Function to give the next Publisher.
      Returns:
      New Publisher that switches to the Publisher returned by next after this Single completes successfully.
    • whenOnSuccess

      public final Single<T> whenOnSuccess(Consumer<? super T> onSuccess)
      Invokes the onSuccess Consumer argument when SingleSource.Subscriber.onSuccess(Object) is called for SingleSource.Subscribers of the returned Single.

      The order in which onSuccess will be invoked relative to SingleSource.Subscriber.onSuccess(Object) is undefined. If you need strict ordering see beforeOnSuccess(Consumer) and afterOnSuccess(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 when SingleSource.Subscriber.onSuccess(Object) is called for SingleSource.Subscribers of the returned Single. MUST NOT throw.
      Returns:
      The new Single.
      See Also:
    • whenOnError

      public final Single<T> whenOnError(Consumer<Throwable> onError)
      Invokes the onError Consumer argument when SingleSource.Subscriber.onError(Throwable) is called for SingleSource.Subscribers of the returned Single.

      The order in which onError will be invoked relative to SingleSource.Subscriber.onError(Throwable) is undefined. If you need strict ordering see beforeOnError(Consumer) and afterOnError(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 when SingleSource.Subscriber.onError(Throwable) is called for SingleSource.Subscribers of the returned Single. MUST NOT throw.
      Returns:
      The new Single.
      See Also:
    • whenFinally

      public final Single<T> whenFinally(Runnable doFinally)
      Invokes the whenFinally Runnable argument exactly once, when any of the following terminal methods are called: for Subscriptions/SingleSource.Subscribers of the returned Single.

      The order in which whenFinally will be invoked relative to the above methods is undefined. If you need strict ordering see beforeFinally(Runnable) and afterFinally(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: for Subscriptions/SingleSource.Subscribers of the returned Single. MUST NOT throw.
      Returns:
      The new Single.
      See Also:
    • whenFinally

      public final Single<T> whenFinally(TerminalSignalConsumer doFinally)
      Invokes the corresponding method on whenFinally TerminalSignalConsumer argument when any of the following terminal methods are called: for Subscriptions/SingleSource.Subscribers of the returned Single.

      The order in which whenFinally will be invoked relative to the above methods is undefined. If you need strict ordering see beforeFinally(TerminalSignalConsumer) and afterFinally(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 returned Single, at most one method of this TerminalSignalConsumer will be invoked.
      Returns:
      The new Single.
      See Also:
    • whenFinally

      public final Single<T> whenFinally(SingleTerminalSignalConsumer<? super T> doFinally)
      Invokes the corresponding method on whenFinally SingleTerminalSignalConsumer argument when any of the following terminal methods are called: for Subscriptions/SingleSource.Subscribers of the returned Single.

      The order in which whenFinally will be invoked relative to the above methods is undefined. If you need strict ordering see beforeFinally(SingleTerminalSignalConsumer) and afterFinally(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 returned Single, at most one method of this SingleTerminalSignalConsumer will be invoked.
      Returns:
      The new Single.
      See Also:
    • whenCancel

      public final Single<T> whenCancel(Runnable onCancel)
      Invokes the onCancel Runnable argument when Cancellable.cancel() is called for Subscriptions of the returned Single.

      The order in which whenFinally will be invoked relative to Cancellable.cancel() is undefined. If you need strict ordering see beforeCancel(Runnable) and afterCancel(Runnable).

      Parameters:
      onCancel - Invoked when Cancellable.cancel() is called for Subscriptions of the returned Single. MUST NOT throw.
      Returns:
      The new Single.
      See Also:
    • timeout

      public final Single<T> timeout(long duration, TimeUnit unit)
      Creates a new Single that will mimic the signals of this Single but will terminate with a TimeoutException if time duration elapses between subscribe and termination. The timer starts when the returned Single is subscribed.

      In the event of timeout any Cancellable from SingleSource.Subscriber.onSubscribe(Cancellable) will be cancelled and the associated SingleSource.Subscriber will be terminated.

      Parameters:
      duration - The time duration which is allowed to elapse before SingleSource.Subscriber.onSuccess(Object).
      unit - The units for duration.
      Returns:
      a new Single that will mimic the signals of this Single but will terminate with a TimeoutException if time duration elapses before SingleSource.Subscriber.onSuccess(Object).
      See Also:
    • timeout

      public final Single<T> timeout(long duration, TimeUnit unit, Executor timeoutExecutor)
      Creates a new Single that will mimic the signals of this Single but will terminate with a TimeoutException if time duration elapses between subscribe and termination. The timer starts when the returned Single is subscribed.

      In the event of timeout any Cancellable from SingleSource.Subscriber.onSubscribe(Cancellable) will be cancelled and the associated SingleSource.Subscriber will be terminated.

      Parameters:
      duration - The time duration which is allowed to elapse before SingleSource.Subscriber.onSuccess(Object).
      unit - The units for duration.
      timeoutExecutor - The Executor to use for managing the timer notifications.
      Returns:
      a new Single that will mimic the signals of this Single but will terminate with a TimeoutException if time duration elapses before SingleSource.Subscriber.onSuccess(Object).
      See Also:
    • timeout

      public final Single<T> timeout(Duration duration)
      Creates a new Single that will mimic the signals of this Single but will terminate with a TimeoutException if time duration elapses between subscribe and termination. The timer starts when the returned Single is subscribed.

      In the event of timeout any Cancellable from SingleSource.Subscriber.onSubscribe(Cancellable) will be cancelled and the associated SingleSource.Subscriber will be terminated. SingleSource.Subscriber will via terminated.

      Parameters:
      duration - The time duration which is allowed to elapse before SingleSource.Subscriber.onSuccess(Object).
      Returns:
      a new Single that will mimic the signals of this Single but will terminate with a TimeoutException if time duration elapses before SingleSource.Subscriber.onSuccess(Object).
      See Also:
    • timeout

      public final Single<T> timeout(Duration duration, Executor timeoutExecutor)
      Creates a new Single that will mimic the signals of this Single but will terminate with a with a TimeoutException if time duration elapses between subscribe and termination. The timer starts when the returned Single is subscribed.

      In the event of timeout any Cancellable from SingleSource.Subscriber.onSubscribe(Cancellable) will be cancelled and the associated SingleSource.Subscriber will be terminated.

      Parameters:
      duration - The time duration which is allowed to elapse before SingleSource.Subscriber.onSuccess(Object).
      timeoutExecutor - The Executor to use for managing the timer notifications.
      Returns:
      a new Single that will mimic the signals of this Single but will terminate with a TimeoutException if time duration elapses before SingleSource.Subscriber.onSuccess(Object).
      See Also:
    • concat

      public final Publisher<T> concat(Single<? extends T> next)
      Returns a Publisher that first emits the result of this Single and then subscribes and emits result of next Single. Any error emitted by this Single or next Single is forwarded to the returned Publisher.

      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;
       
      Parameters:
      next - Single to concat.
      Returns:
      New Publisher that first emits the result of this Single and then subscribes and emits result of next Single.
    • concat

      public final Single<T> concat(Completable next)
      Returns a Single that emits the result of this Single after next Completable terminates successfully. next Completable will only be subscribed to after this Single terminates successfully. Any error emitted by this Single or next Completable is forwarded to the returned Single.

      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 - Completable to concat.
      Returns:
      New Single that emits the result of this Single after next Completable terminates successfully.
    • concat

      public final Publisher<T> concat(Publisher<? extends T> next)
      Returns a Publisher that first emits the result of this Single and then subscribes and emits all elements from next Publisher. Any error emitted by this Single or next Publisher is forwarded to the returned Publisher.

      Note: this operator triggers subscribe to the next Publisher as soon as this Single completes successfully.

      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;
       
      Parameters:
      next - Publisher to concat.
      Returns:
      New Publisher that first emits the result of this Single and then subscribes and emits all elements from next Publisher.
      See Also:
    • concat

      @Deprecated public final Publisher<T> concat(Publisher<? extends T> next, boolean deferSubscribe)
      Returns a Publisher that first emits the result of this Single and then subscribes and emits all elements from next Publisher. Any error emitted by this Single or next Publisher is forwarded to the returned Publisher.

      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;
       
      Parameters:
      next - Publisher to concat.
      deferSubscribe - if true subscribe to the next Publisher will be deferred until demand is received. Otherwise, it subscribes to the next Publisher as soon as this Single completes successfully. Choosing the deferred (true) behavior is important if the next Publisher does not or might not support multiple subscribers (non-replayable). Choosing the immediate subscribe (false) behavior may have better performance and may be a preferable choice for replayable Publisher(s) or when eager subscribe is beneficial.
      Returns:
      New Publisher that first emits the result of this Single and then subscribes and emits all elements from next Publisher.
    • concatDeferSubscribe

      public final Publisher<T> concatDeferSubscribe(Publisher<? extends T> next)
      This method is like concat(Publisher) subscribe to the next Publisher will be deferred until demand is received (at least 2 items requested).

      Choosing the deferred behavior is important if the next Publisher does not or might not support multiple subscribers (non-replayable). Choosing the immediate subscribe (concat(Publisher)) behavior may have better performance and may be a preferable choice for replayable Publisher(s) or when eager subscribe is beneficial.

      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;
       
      Parameters:
      next - Publisher to concat.
      Returns:
      New Publisher that first emits the result of this Single and then subscribes and emits all elements from next Publisher.
      See Also:
    • concatPropagateCancel

      public final Publisher<T> concatPropagateCancel(Publisher<? extends T> next)
      This method is like concat(Publisher) except next will be subscribed to and cancelled if this Publisher is cancelled or terminates with SingleSource.Subscriber.onError(Throwable).

      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;
       
      Parameters:
      next - Publisher to concat. Will be subscribed to and cancelled if this Publisher is cancelled or terminates with SingleSource.Subscriber.onError(Throwable).
      Returns:
      New Publisher that first emits the result of this Single and then subscribes and emits all elements from next Publisher.
      See Also:
    • zipWith

      public final <T2, R> Single<R> zipWith(Single<? extends T2> other, BiFunction<? super T,? super T2,? extends R> zipper)
      Create a new Single that emits the results of a specified zipper BiFunction to items emitted by this and other.

      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 of other.
      R - The result type of the zipper.
      Parameters:
      other - The other Single to zip with.
      zipper - Used to combine the completed results for each item from singles.
      Returns:
      a new Single that emits the results of a specified zipper BiFunction to items emitted by this and other.
      See Also:
    • zipWithDelayError

      public final <T2, R> Single<R> zipWithDelayError(Single<? extends T2> other, BiFunction<? super T,? super T2,? extends R> zipper)
      Create a new Single that emits the results of a specified zipper BiFunction to items emitted by this and other. If any of the Singles terminate with an error, the returned Single will wait for termination till all the other Singles have been subscribed and terminated, and then terminate with the first error.

      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 of other.
      R - The result type of the zipper.
      Parameters:
      other - The other Single to zip with.
      zipper - Used to combine the completed results for each item from singles.
      Returns:
      a new Single that emits the results of a specified zipper BiFunction to items emitted by this and other.
      See Also:
    • retry

      public final Single<T> retry(BiIntPredicate<Throwable> shouldRetry)
      Re-subscribes to this Single if an error is emitted and the passed BiIntPredicate returns true.
       This method may result in a StackOverflowError if too many consecutive calls are made. This can be
       avoided by trampolining the call stack onto an Executor. For example:
         retryWhen((i, cause) -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())
       
      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 - BiIntPredicate that given the retry count and the most recent Throwable emitted from this Single determines if the operation should be retried.
      Returns:
      A Single that emits the result from this Single or re-subscribes if an error is emitted and if the passed BiIntPredicate returned true.
      See Also:
    • retryWhen

      public final Single<T> retryWhen(BiIntFunction<Throwable,? extends Completable> retryWhen)
      Re-subscribes to this Single if an error is emitted and the Completable returned by the supplied BiIntFunction completes successfully. If the returned Completable emits an error, the returned Single terminates with that error.
       This method may result in a StackOverflowError if too many consecutive calls are made. This can be
       avoided by trampolining the call stack onto an Executor. For example:
         retryWhen((i, cause) -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())
       
      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 - BiIntFunction that given the retry count and the most recent Throwable emitted from this Single returns a Completable. If this Completable emits an error, that error is emitted from the returned Single, otherwise, original Single is re-subscribed when this Completable completes.
      Returns:
      A Single that emits the result from this Single or re-subscribes if an error is emitted and Completable returned by BiIntFunction completes successfully.
      See Also:
    • repeat

      public final Publisher<T> repeat(IntPredicate shouldRepeat)
      Re-subscribes to this Single when it completes and the passed IntPredicate returns true.
       This method may result in a StackOverflowError if too many consecutive calls are made. This can be
       avoided by trampolining the call stack onto an Executor. For example:
         repeatWhen(i -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())
       
      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 - IntPredicate that given the repetition count returns true if the operation should be repeated.
      Returns:
      A Publisher that emits all items from this Single and from all re-subscriptions whenever the operation is repeated.
      See Also:
    • repeat

      public final Publisher<T> repeat(BiIntPredicate<? super T> shouldRepeat)
      Re-subscribes to this Single when it completes and the passed IntPredicate returns true.
       This method may result in a StackOverflowError if too many consecutive calls are made. This can be
       avoided by trampolining the call stack onto an Executor. For example:
         repeatWhen(i -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())
       
      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;
           T result;
           do {
               result = resultOfThisSingle();
               results.add(result);
           } while (shouldRepeat.test(++i, result));
           return results;
       
      Parameters:
      shouldRepeat - BiIntPredicate that given the repetition count and value from the current iteration returns true if the operation should be repeated.
      Returns:
      A Publisher that emits all items from this Single and from all re-subscriptions whenever the operation is repeated.
      See Also:
    • repeatWhen

      public final Publisher<T> repeatWhen(IntFunction<? extends Completable> repeatWhen)
      Re-subscribes to this Single when it completes and the Completable returned by the supplied IntFunction completes successfully. If the returned Completable emits an error, the returned Single emits an error.
       This method may result in a StackOverflowError if too many consecutive calls are made. This can be
       avoided by trampolining the call stack onto an Executor. For example:
         repeatWhen(i -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())
       
      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 - IntFunction that given the repetition count returns a Completable. If this Completable emits an error repeat is terminated, otherwise, original Single is re-subscribed when this Completable completes.
      Returns:
      A Publisher that emits all items from this Single and from all re-subscriptions whenever the operation is repeated.
      See Also:
    • repeatWhen

      public final Publisher<T> repeatWhen(BiIntFunction<? super T,? extends Completable> repeatWhen)
      Re-subscribes to this Single when it completes and the Completable returned by the supplied BiIntFunction completes successfully.
       This method may result in a StackOverflowError if too many consecutive calls are made. This can be
       avoided by trampolining the call stack onto an Executor. For example:
         repeatWhen(i -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())
       
      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) {
               T result = resultOfThisSingle();
               try {
                   repeatWhen.apply(++i, result); // Either throws or completes normally
               } catch (Throwable cause) {
                   break;
               }
           }
           return results;
       
      Parameters:
      repeatWhen - BiIntFunction that given the repetition count and value from the current iteration returns a Completable. If this Completable emits an error repeat is terminated, otherwise, original Single is re-subscribed when this Completable completes.
      Returns:
      A Publisher that emits all items from this Single and from all re-subscriptions whenever the operation is repeated.
      See Also:
    • cache

      public final Single<T> cache()
      Create a Single that subscribes a single time upstream but allows for multiple downstream SingleSource.Subscribers. The terminal signal will be cached and delivered to each downstream SingleSource.Subscriber.

      In sequential programming this is similar to the following:

      
           T result = resultOfThisSingle();
           List<T> multiResults = ...; // simulating multiple Subscribers
           for (int i = 0; i < expectedSubscribers; ++i) {
               multiResults.add(result);
           }
           return multiResults;
       
      Returns:
      a Single that subscribes a single time upstream but allows for multiple downstream SingleSource.Subscribers. The terminal signal will be cached and delivered to each downstream SingleSource.Subscriber.
      See Also:
    • cache

      public final Single<T> cache(int minSubscribers)
      Create a Single that subscribes a single time upstream but allows for multiple downstream SingleSource.Subscribers. The terminal signal will be cached and delivered to each downstream SingleSource.Subscriber.

      In sequential programming this is similar to the following:

      
           T result = resultOfThisSingle();
           List<T> multiResults = ...; // simulating multiple Subscribers
           for (int i = 0; i < expectedSubscribers; ++i) {
               multiResults.add(result);
           }
           return multiResults;
       
      Parameters:
      minSubscribers - The upstream subscribe operation will not happen until after this many SingleSource.Subscriber subscribe to the return value.
      Returns:
      a Single that subscribes a single time upstream but allows for multiple downstream SingleSource.Subscribers. The terminal signal will be cached and delivered to each downstream SingleSource.Subscriber.
      See Also:
    • cache

      public final Single<T> cache(int minSubscribers, boolean cancelUpstream)
      Create a Single that subscribes a single time upstream but allows for multiple downstream SingleSource.Subscribers. The terminal signal will be cached and delivered to each downstream SingleSource.Subscriber.

      In sequential programming this is similar to the following:

      
           T result = resultOfThisSingle();
           List<T> multiResults = ...; // simulating multiple Subscribers
           for (int i = 0; i < expectedSubscribers; ++i) {
               multiResults.add(result);
           }
           return multiResults;
       
      Parameters:
      minSubscribers - The upstream subscribe operation will not happen until after this many SingleSource.Subscriber subscribe to the return value.
      cancelUpstream - true if upstream should be cancelled when all downstream SingleSource.Subscribers cancel. false means that cancel will not be propagated upstream even if all downstream SingleSource.Subscribers cancel, and the upstream Subscription will stay valid until termination.
      Returns:
      a Single that subscribes a single time upstream but allows for multiple downstream SingleSource.Subscribers. The terminal signal will be cached and delivered to each downstream SingleSource.Subscriber.
      See Also:
    • cache

      public final Single<T> cache(int minSubscribers, boolean cancelUpstream, BiFunction<T,Throwable,Completable> terminalResubscribe)
      Create a Single that subscribes a single time upstream but allows for multiple downstream SingleSource.Subscribers. The terminal signal will be cached and delivered to each downstream SingleSource.Subscriber.

      In sequential programming this is similar to the following:

      
           T result = resultOfThisSingle();
           List<T> multiResults = ...; // simulating multiple Subscribers
           for (int i = 0; i < expectedSubscribers; ++i) {
               multiResults.add(result);
           }
           return multiResults;
       
      Parameters:
      minSubscribers - The upstream subscribe operation will not happen until after this many SingleSource.Subscriber subscribe to the return value.
      cancelUpstream - true if upstream should be cancelled when all downstream SingleSource.Subscribers cancel. false means that cancel will not be propagated upstream even if all downstream SingleSource.Subscribers cancel, and the upstream Subscription will stay valid until termination.
      terminalResubscribe - A BiFunction that is invoked when a terminal signal arrives from upstream, and returns a Completable whose termination resets the state of the returned Single and allows for downstream resubscribing.
      Returns:
      a Single that subscribes a single time upstream but allows for multiple downstream SingleSource.Subscribers. The terminal signal will be cached and delivered to each downstream SingleSource.Subscriber.
      See Also:
    • beforeOnSubscribe

      public final Single<T> beforeOnSubscribe(Consumer<Cancellable> onSubscribe)
      Invokes the onSubscribe Consumer argument before SingleSource.Subscriber.onSubscribe(Cancellable) is called for SingleSource.Subscribers of the returned Single.
      Parameters:
      onSubscribe - Invoked before SingleSource.Subscriber.onSubscribe(Cancellable) is called for SingleSource.Subscribers of the returned Single. MUST NOT throw.
      Returns:
      The new Single.
    • beforeOnSuccess

      public final Single<T> beforeOnSuccess(Consumer<? super T> onSuccess)
      Invokes the onSuccess Consumer argument before SingleSource.Subscriber.onSuccess(Object) is called for SingleSource.Subscribers of the returned Single.

      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 before SingleSource.Subscriber.onSuccess(Object) is called for SingleSource.Subscribers of the returned Single. MUST NOT throw.
      Returns:
      The new Single.
    • beforeOnError

      public final Single<T> beforeOnError(Consumer<Throwable> onError)
      Invokes the onError Consumer argument before SingleSource.Subscriber.onError(Throwable) is called for SingleSource.Subscribers of the returned Single.

      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 before SingleSource.Subscriber.onError(Throwable) is called for SingleSource.Subscribers of the returned Single. MUST NOT throw.
      Returns:
      The new Single.
    • beforeCancel

      public final Single<T> beforeCancel(Runnable onCancel)
      Invokes the onCancel Runnable argument before Cancellable.cancel() is called for Subscriptions of the returned Single.
      Parameters:
      onCancel - Invoked before Cancellable.cancel() is called for Subscriptions of the returned Single. MUST NOT throw.
      Returns:
      The new Single.
    • beforeFinally

      public final Single<T> beforeFinally(Runnable doFinally)
      Invokes the whenFinally Runnable argument before any of the following terminal methods are called: for Subscriptions/SingleSource.Subscribers of the returned Single.

      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: for Subscriptions/SingleSource.Subscribers of the returned Single. MUST NOT throw.
      Returns:
      The new Single.
      See Also:
    • beforeFinally

      public final Single<T> beforeFinally(TerminalSignalConsumer doFinally)
      Invokes the corresponding method on beforeFinally TerminalSignalConsumer argument before any of the following terminal methods are called: for Subscriptions/SingleSource.Subscribers of the returned Single.

      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 returned Single, at most one method of this TerminalSignalConsumer will be invoked.
      Returns:
      The new Single.
      See Also:
    • beforeFinally

      public final Single<T> beforeFinally(SingleTerminalSignalConsumer<? super T> doFinally)
      Invokes the corresponding method on beforeFinally SingleTerminalSignalConsumer argument before any of the following terminal methods are called: for Subscriptions/SingleSource.Subscribers of the returned Single.

      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 returned Single, at most one method of this SingleTerminalSignalConsumer will be invoked.
      Returns:
      The new Single.
      See Also:
    • beforeSubscriber

      public final Single<T> beforeSubscriber(Supplier<? extends SingleSource.Subscriber<? super T>> subscriberSupplier)
      Creates a new SingleSource.Subscriber (via the subscriberSupplier argument) on each call to subscribe and invokes all the SingleSource.Subscriber methods before the SingleSource.Subscribers of the returned Single.
      Parameters:
      subscriberSupplier - Creates a new SingleSource.Subscriber on each call to subscribe and invokes all the SingleSource.Subscriber methods before the SingleSource.Subscribers of the returned Single. SingleSource.Subscriber methods MUST NOT throw.
      Returns:
      The new Single.
    • afterOnSubscribe

      public final Single<T> afterOnSubscribe(Consumer<Cancellable> onSubscribe)
      Invokes the onSubscribe Consumer argument after SingleSource.Subscriber.onSubscribe(Cancellable) is called for SingleSource.Subscribers of the returned Single.
      Parameters:
      onSubscribe - Invoked after SingleSource.Subscriber.onSubscribe(Cancellable) is called for SingleSource.Subscribers of the returned Single. MUST NOT throw.
      Returns:
      The new Single.
    • whenOnSubscribe

      public final Single<T> whenOnSubscribe(Consumer<Cancellable> onSubscribe)
      Invokes the onSubscribe Consumer argument when SingleSource.Subscriber.onSubscribe(Cancellable) is called for SingleSource.Subscribers of the returned Single.

      The order in which onSubscribe will be invoked relative to SingleSource.Subscriber.onSubscribe(Cancellable) is undefined. If you need strict ordering see beforeOnSubscribe(Consumer) and afterOnSubscribe(Consumer).

      Parameters:
      onSubscribe - Invoked when SingleSource.Subscriber.onSubscribe(Cancellable) is called for SingleSource.Subscribers of the returned Single. MUST NOT throw.
      Returns:
      The new Single.
      See Also:
    • afterOnSuccess

      public final Single<T> afterOnSuccess(Consumer<? super T> onSuccess)
      Invokes the onSuccess Consumer argument after SingleSource.Subscriber.onSuccess(Object) is called for SingleSource.Subscribers of the returned Single.

      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 after SingleSource.Subscriber.onSuccess(Object) is called for SingleSource.Subscribers of the returned Single. MUST NOT throw.
      Returns:
      The new Single.
    • afterOnError

      public final Single<T> afterOnError(Consumer<Throwable> onError)
      Invokes the onError Consumer argument after SingleSource.Subscriber.onError(Throwable) is called for SingleSource.Subscribers of the returned Single.

      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 after SingleSource.Subscriber.onError(Throwable) is called for SingleSource.Subscribers of the returned Single. MUST NOT throw.
      Returns:
      The new Single.
    • afterCancel

      public final Single<T> afterCancel(Runnable onCancel)
      Invokes the onCancel Runnable argument after Cancellable.cancel() is called for Subscriptions of the returned Single.
      Parameters:
      onCancel - Invoked after Cancellable.cancel() is called for Subscriptions of the returned Single. MUST NOT throw.
      Returns:
      The new Single.
    • afterFinally

      public final Single<T> afterFinally(Runnable doFinally)
      Invokes the whenFinally Runnable argument after any of the following terminal methods are called: for Subscriptions/SingleSource.Subscribers of the returned Single.

      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: for Subscriptions/SingleSource.Subscribers of the returned Single. MUST NOT throw.
      Returns:
      The new Single.
      See Also:
    • afterFinally

      public final Single<T> afterFinally(TerminalSignalConsumer doFinally)
      Invokes the corresponding method on afterFinally TerminalSignalConsumer argument after any of the following terminal methods are called: for Subscriptions/SingleSource.Subscribers of the returned Single.

      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 returned Single, at most one method of this TerminalSignalConsumer will be invoked.
      Returns:
      The new Single.
      See Also:
    • afterFinally

      public final Single<T> afterFinally(SingleTerminalSignalConsumer<? super T> doFinally)
      Invokes the corresponding method on afterFinally SingleTerminalSignalConsumer argument after any of the following terminal methods are called: for Subscriptions/SingleSource.Subscribers of the returned Single.

      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 returned Single, at most one method of this SingleTerminalSignalConsumer will be invoked.
      Returns:
      The new Single.
      See Also:
    • afterSubscriber

      public final Single<T> afterSubscriber(Supplier<? extends SingleSource.Subscriber<? super T>> subscriberSupplier)
      Creates a new SingleSource.Subscriber (via the subscriberSupplier argument) on each call to subscribe and invokes all the SingleSource.Subscriber methods after the SingleSource.Subscribers of the returned Single.
      Parameters:
      subscriberSupplier - Creates a new SingleSource.Subscriber on each call to subscribe and invokes all the SingleSource.Subscriber methods after the SingleSource.Subscribers of the returned Single. SingleSource.Subscriber methods MUST NOT throw.
      Returns:
      The new Single.
    • whenSubscriber

      public final Single<T> whenSubscriber(Supplier<? extends SingleSource.Subscriber<? super T>> subscriberSupplier)
      Creates a new SingleSource.Subscriber (via the subscriberSupplier argument) for each new subscribe and invokes methods on that SingleSource.Subscriber when the corresponding methods are called for SingleSource.Subscribers of the returned Single.
      Parameters:
      subscriberSupplier - Creates a new SingleSource.Subscriber for each new subscribe and invokes methods on that SingleSource.Subscriber when the corresponding methods are called for SingleSource.Subscribers of the returned Single. SingleSource.Subscriber methods MUST NOT throw.
      Returns:
      The new Single.
    • publishOn

      public final Single<T> publishOn(Executor executor)
      Creates a new Single that will use the passed Executor to invoke all SingleSource.Subscriber methods. This method does not override preceding Executors, if any, specified for this Single. Only subsequent operations, if any, added in this execution chain will use this Executor.

      Note: unlike publishOn(io.servicetalk.concurrent.Executor, BooleanSupplier), current operator always enforces offloading to the passed Executor.

      Parameters:
      executor - Executor to use.
      Returns:
      A new Single that will use the passed Executor to invoke all SingleSource.Subscriber methods.
      See Also:
    • publishOn

      public final Single<T> publishOn(Executor executor, BooleanSupplier shouldOffload)
      Creates a new Single that may use the passed Executor to invoke all SingleSource.Subscriber methods. This method does not override preceding Executors, if any, specified for this Single. Only subsequent operations, if any, added in this execution chain will use this Executor.

      Note: unlike publishOn(io.servicetalk.concurrent.Executor), current operator may skip offloading to the passed Executor, depending on the result of the BooleanSupplier hint.

      Parameters:
      executor - Executor to use.
      shouldOffload - Provides a hint whether offloading to the executor can be omitted or not. Offloading may still occur even if false is returned in order to preserve signal ordering.
      Returns:
      A new Single that may use the passed Executor to invoke all SingleSource.Subscriber methods.
      See Also:
    • subscribeOn

      public final Single<T> subscribeOn(Executor executor)
      Creates a new Single that will use the passed Executor to invoke the following methods: This method does not override preceding Executors, if any, specified for this Single. Only subsequent operations, if any, added in this execution chain will use this Executor.

      Note: unlike subscribeOn(io.servicetalk.concurrent.Executor, BooleanSupplier), current operator always enforces offloading to the passed Executor.

      Parameters:
      executor - Executor to use.
      Returns:
      A new Single that will use the passed Executor to invoke all methods of Cancellable and handleSubscribe(SingleSource.Subscriber).
      See Also:
    • subscribeOn

      public final Single<T> subscribeOn(Executor executor, BooleanSupplier shouldOffload)
      Creates a new Single that may use the passed Executor to invoke the following methods: This method does not override preceding Executors, if any, specified for this Single. Only subsequent operations, if any, added in this execution chain will use this Executor.

      Note: unlike subscribeOn(io.servicetalk.concurrent.Executor), current operator may skip offloading to the passed Executor, depending on the result of the BooleanSupplier hint.

      Parameters:
      executor - Executor to use.
      shouldOffload - Provides a hint whether offloading to the executor can be omitted or not. Offloading may still occur even if false is returned in order to preserve signal ordering.
      Returns:
      A new Single that may use the passed Executor to invoke all methods of Cancellable and handleSubscribe(SingleSource.Subscriber).
      See Also:
    • shareContextOnSubscribe

      public final Single<T> shareContextOnSubscribe()
      Signifies that when the returned Single is subscribed to, the AsyncContext will be shared instead of making a copy.

      This operator only impacts behavior if the returned Single is subscribed directly after this operator, that means this must be the "last operator" in the chain for this to have an impact.

      Returns:
      A Single that will share the AsyncContext instead of making a copy when subscribed to.
    • setContextOnSubscribe

      public final Single<T> setContextOnSubscribe(ContextMap context)
      Specify the ContextMap to use for AsyncContext when the returned Single is subscribed to.

      This operator only impacts behavior if the returned Single is subscribed directly after this operator, that means this must be the "last operator" in the chain for this to have an impact.

      Parameters:
      context - The ContextMap to use for AsyncContext when subscribed.
      Returns:
      A Single that will use the ContextMap for AsyncContext when subscribed.
    • 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 Single which will wrap the SingleSource.Subscriber using the provided operator argument before subscribing to this Single.

      
           Single<X> pub = ...;
           pub.map(..) // A
              .liftSync(original -> modified)
              .afterFinally(..) // B
       
      The original -> modified "operator" MUST be "synchronous" in that it does not interact with the original SingleSource.Subscriber from outside the modified SingleSource.Subscriber or Cancellable threads. That is to say this operator will not impact the Executor constraints already in place between A and B above. If you need asynchronous behavior, or are unsure, see liftAsync(SingleOperator).
      Type Parameters:
      R - Type of the items emitted by the returned Single.
      Parameters:
      operator - The custom operator logic. The input is the "original" SingleSource.Subscriber to this Single and the return is the "modified" SingleSource.Subscriber that provides custom operator business logic.
      Returns:
      a Single which when subscribed, the operator argument will be used to wrap the SingleSource.Subscriber before subscribing to this Single.
      See Also:
    • 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 Single which will wrap the SingleSource.Subscriber using the provided operator argument before subscribing to this Single.

      
           Publisher<X> pub = ...;
           pub.map(..) // Aw
              .liftAsync(original -> modified)
              .afterFinally(..) // B
       
      The original -> modified "operator" MAY be "asynchronous" in that it may interact with the original SingleSource.Subscriber from outside the modified SingleSource.Subscriber or Cancellable threads. More specifically: This behavior exists to prevent blocking code negatively impacting the thread that powers the upstream source of data (e.g. an EventLoop).
      Type Parameters:
      R - Type of the items emitted by the returned Single.
      Parameters:
      operator - The custom operator logic. The input is the "original" SingleSource.Subscriber to this Single and the return is the "modified" SingleSource.Subscriber that provides custom operator business logic.
      Returns:
      a Single which when subscribed, the operator argument will be used to wrap the SingleSource.Subscriber before subscribing to this Single.
      See Also:
    • ambWith

      public final Single<T> ambWith(Single<T> other)
      Creates a new Single that terminates with the result (either success or error) of either this Single or the passed other Single, whichever terminates first. Therefore, the result is said to be ambiguous relative to which source it originated from. After the first source terminates, only the non-terminated source will be cancelled.

      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();
            }
       
      Parameters:
      other - Single to subscribe to and race with this Single to propagate to the return value.
      Returns:
      A new Single that terminates with the result (either success or error) of either this Single or the passed other Single, whichever terminates first. Therefore, the result is said to be ambiguous relative to which source it originated from.
      See Also:
    • toPublisher

      public final Publisher<T> toPublisher()
      Converts this Single to a Publisher.
      Returns:
      A Publisher that emits at most a single item which is emitted by this Single.
    • toCompletable

      public final Completable toCompletable()
      Ignores the result of this Single and forwards the termination signal to the returned Completable.
      Returns:
      A Completable that mirrors the terminal signal from this Single.
    • ignoreElement

      public final Completable ignoreElement()
      Ignores the result of this Single and forwards the termination signal to the returned Completable.
      Returns:
      A Completable that mirrors the terminal signal from this Single.
    • toCompletionStage

      public final CompletionStage<T> toCompletionStage()
      Convert this Single to a CompletionStage.
      Returns:
      A CompletionStage that mirrors the terminal signal from this Single.
    • toFuture

      public final Future<T> toFuture()
      Convert this Single to a Future.
      Returns:
      A Future that mirrors the terminal signal from this Single.
    • subscribeInternal

      protected final void subscribeInternal(SingleSource.Subscriber<? super T> subscriber)
      A internal subscribe method similar to SingleSource.subscribe(Subscriber) which can be used by different implementations to subscribe.
      Parameters:
      subscriber - SingleSource.Subscriber to subscribe for the result.
    • subscribe

      public final Cancellable subscribe(Consumer<? super T> resultConsumer)
      Subscribe to this Single, emit the result to the passed Consumer and log any SingleSource.Subscriber.onError(Throwable) at debug level.
      Parameters:
      resultConsumer - Consumer to accept the result of this Single if it succeeds.
      Returns:
      Cancellable used to invoke Cancellable.cancel() on the parameter of SingleSource.Subscriber.onSubscribe(Cancellable) for this Single.
    • subscribe

      public final Cancellable subscribe(Consumer<? super T> resultConsumer, Consumer<? super Throwable> errorConsumer)
      Subscribe to this Single, emit the result or error to one of the passed Consumers.
      Parameters:
      resultConsumer - Consumer to accept the result of this Single if it succeeds.
      errorConsumer - Consumer to accept the error of this Single if it fails.
      Returns:
      Cancellable used to invoke Cancellable.cancel() on the parameter of SingleSource.Subscriber.onSubscribe(Cancellable) for this Single.
    • handleSubscribe

      protected abstract void handleSubscribe(SingleSource.Subscriber<? super T> subscriber)
      Handles a subscriber to this Single.
      Parameters:
      subscriber - the subscriber.
    • succeeded

      public static <T> Single<T> succeeded(@Nullable T value)
      Creates a realized Single which always completes successfully with the provided value.
      Type Parameters:
      T - Type of the Single.
      Parameters:
      value - result of the Single.
      Returns:
      A new Single.
    • fromCallable

      public static <T> Single<T> fromCallable(Callable<T> callable)
      Creates a Single which when subscribed will invoke Callable.call() on the passed Callable and emit the value returned by that invocation from the returned Single. Any error emitted by the Callable will terminate the returned Single with the same error.

      Blocking inside Callable.call() will in turn block the subscribe call to the returned Single. If this behavior is undesirable then the returned Single should be offloaded using subscribeOn(io.servicetalk.concurrent.Executor) which offloads the subscribe call.

      Type Parameters:
      T - Type of the Single.
      Parameters:
      callable - Callable which supplies the result of the Single.
      Returns:
      A new Single.
    • fromSupplier

      public static <T> Single<T> fromSupplier(Supplier<T> supplier)
      Creates a Single which when subscribed will invoke Supplier.get() on the passed Supplier and emit the value returned by that invocation from the returned Single. Any error emitted by the Supplier will terminate the returned Single with the same error.

      Blocking inside Supplier.get() will in turn block the subscribe call to the returned Single. If this behavior is undesirable then the returned Single should be offloaded using subscribeOn(io.servicetalk.concurrent.Executor) which offloads the subscribe call.

      Type Parameters:
      T - Type of the Single.
      Parameters:
      supplier - Supplier which supplies the result of the Single.
      Returns:
      A new Single.
    • failed

      public static <T> Single<T> failed(Throwable cause)
      Creates a realized Single which always completes with the provided error cause.
      Type Parameters:
      T - Type of the Single.
      Parameters:
      cause - result of the Single.
      Returns:
      A new Single.
    • never

      public static <T> Single<T> never()
      Creates a Single that never terminates.
      Type Parameters:
      T - Type of the Single.
      Returns:
      A new Single.
    • defer

      public static <T> Single<T> defer(Supplier<? extends Single<? extends T>> singleSupplier)
      Defer creation of a Single till it is subscribed to.
      Type Parameters:
      T - Type of the Single.
      Parameters:
      singleSupplier - Supplier to create a new Single every time the returned Single is subscribed.
      Returns:
      A new Single that creates a new Single using singleSupplier every time it is subscribed and forwards all items and terminal events from the newly created Single to its SingleSource.Subscriber.
    • fromFuture

      public static <T> Single<T> fromFuture(Future<? extends T> future)
      Convert from a Future to a Single via Future.get().

      Note that because Future only 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 if Cancellable.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 the Future provides when complete.
      Parameters:
      future - The Future to convert.
      Returns:
      A Single that derives results from Future.
      See Also:
    • collectUnordered

      public static <T> Single<Collection<T>> collectUnordered(Iterable<? extends Single<? extends T>> singles)
      Asynchronously collects results of individual Singles returned by the passed Iterable into a single Collection.

      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, returned Single will immediately terminate with that error. In such a case, any in progress Singles will be cancelled. In order to delay error termination use collectUnorderedDelayError(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 individual Singles
      Parameters:
      singles - Iterable of Singles, results of which are to be collected.
      Returns:
      A Single producing a Collection of all values produced by the individual Singles. There is no guarantee of the order of the values in the produced Collection as compared to the order of Singles passed to this method.
    • collectUnordered

      @SafeVarargs public static <T> Single<Collection<T>> collectUnordered(Single<? extends T>... singles)
      Asynchronously collects results of the passed Singles into a single Collection.

      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, returned Single will immediately terminate with that error. In such a case, any in progress Singles will be cancelled. In order to delay error termination use collectUnorderedDelayError(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 individual Singles
      Parameters:
      singles - Singles, results of which are to be collected.
      Returns:
      A Single producing a Collection of all values produced by the individual Singles. There is no guarantee of the order of the values in the produced Collection as compared to the order of Singles passed to this method.
    • collectUnordered

      public static <T> Single<Collection<T>> collectUnordered(Iterable<? extends Single<? extends T>> singles, int maxConcurrency)
      Asynchronously collects results of individual Singles returned by the passed Iterable into a single Collection.

      If any of the Singles terminate with an error, returned Single will immediately terminate with that error. In such a case, any in progress Singles will be cancelled. In order to delay error termination use collectUnorderedDelayError(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 individual Singles
      Parameters:
      singles - Iterable of Singles, results of which are to be collected.
      maxConcurrency - Maximum number of Singles that will be active at any point in time.
      Returns:
      A Single producing a Collection of all values produced by the individual Singles. There is no guarantee of the order of the values in the produced Collection as compared to the order of Singles passed to this method.
    • collectUnordered

      @SafeVarargs public static <T> Single<Collection<T>> collectUnordered(int maxConcurrency, Single<? extends T>... singles)
      Asynchronously collects results of the passed Singles into a single Collection.

      If any of the Singles terminate with an error, returned Single will immediately terminate with that error. In such a case, any in progress Singles will be cancelled. In order to delay error termination use collectUnorderedDelayError(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 individual Singles
      Parameters:
      maxConcurrency - Maximum number of Singles that will be active at any point in time.
      singles - Singles, results of which are to be collected.
      Returns:
      A Single producing a Collection of all values produced by the individual Singles. There is no guarantee of the order of the values in the produced Collection as compared to the order of Singles passed to this method.
    • collectUnorderedDelayError

      public static <T> Single<Collection<T>> collectUnorderedDelayError(Iterable<? extends Single<? extends T>> singles)
      Asynchronously collects results of individual Singles returned by the passed Iterable into a single Collection.

      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, returned Single will wait for termination till all the other Singles have been subscribed and terminated. If it is expected for the returned Single to terminate on the first failing Single, 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 individual Singles
      Parameters:
      singles - Iterable of Singles, results of which are to be collected.
      Returns:
      A Single producing a Collection of all values produced by the individual Singles. There is no guarantee of the order of the values in the produced Collection as compared to the order of Singles passed to this method.
    • collectUnorderedDelayError

      @SafeVarargs public static <T> Single<Collection<T>> collectUnorderedDelayError(Single<? extends T>... singles)
      Asynchronously collects results of the passed Singles into a single Collection.

      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, returned Single will wait for termination till all the other Singles have been subscribed and terminated. If it is expected for the returned Single to terminate on the first failing Single, 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 individual Singles
      Parameters:
      singles - Singles, results of which are to be collected.
      Returns:
      A Single producing a Collection of all values produced by the individual Singles. There is no guarantee of the order of the values in the produced Collection as compared to the order of Singles passed to this method.
    • collectUnorderedDelayError

      public static <T> Single<Collection<T>> collectUnorderedDelayError(Iterable<? extends Single<? extends T>> singles, int maxConcurrency)
      Asynchronously collects results of individual Singles returned by the passed Iterable into a single Collection.

      If any of the Singles terminate with an error, returned Single will wait for termination till all the other Singles have been subscribed and terminated. If it is expected for the returned Single to terminate on the first failing Single, 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 individual Singles
      Parameters:
      singles - Iterable of Singles, results of which are to be collected.
      maxConcurrency - Maximum number of Singles that will be active at any point in time.
      Returns:
      A Single producing a Collection of all values produced by the individual Singles. There is no guarantee of the order of the values in the produced Collection as compared to the order of Singles passed to this method.
    • collectUnorderedDelayError

      @SafeVarargs public static <T> Single<Collection<T>> collectUnorderedDelayError(int maxConcurrency, Single<? extends T>... singles)
      Asynchronously collects results of the passed Singles into a single Collection.

      If any of the Singles terminate with an error, returned Single will wait for termination till all the other Singles have been subscribed and terminated. If it is expected for the returned Single to terminate on the first failing Single, 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 individual Singles
      Parameters:
      maxConcurrency - Maximum number of Singles that will be active at any point in time.
      singles - Singles, results of which are to be collected.
      Returns:
      A Single producing a Collection of all values produced by the individual Singles. There is no guarantee of the order of the values in the produced Collection as compared to the order of Singles passed to this method.
    • fromStage

      public static <T> Single<T> fromStage(CompletionStage<? extends T> stage)
      Convert from a CompletionStage to a Single.

      A best effort is made to propagate Cancellable.cancel() to the CompletionStage. Cancellation for CompletionStage implementations 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 an Executor is appropriate.

      Type Parameters:
      T - The data type the CompletionStage provides when complete.
      Parameters:
      stage - The CompletionStage to convert.
      Returns:
      A Single that derives results from CompletionStage.
    • amb

      @SafeVarargs public static <T> Single<T> amb(Single<? extends T>... singles)
      Creates a new Single that terminates with the result (either success or error) of whichever amongst the passed singles that terminates first. Therefore, the result is said to be ambiguous relative to which source it originated from. After the first source terminates, only the non-terminated sources will be cancelled.

      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 individual Singles
      Parameters:
      singles - Singles to subscribe to and race to propagate to the return value.
      Returns:
      A new Single that terminates with the result (either success or error) of whichever amongst the passed singles that terminates first. Therefore, the result is said to be ambiguous relative to which source it originated from.
      See Also:
    • amb

      public static <T> Single<T> amb(Iterable<Single<? extends T>> singles)
      Creates a new Single that terminates with the result (either success or error) of whichever amongst the passed singles that terminates first. Therefore, the result is said to be ambiguous relative to which source it originated from. After the first source terminates, only the non-terminated sources will be cancelled.

      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 individual Singles
      Parameters:
      singles - Singles to subscribe to and race to propagate to the return value.
      Returns:
      A new Single that terminates with the result (either success or error) of whichever amongst the passed singles that terminates first. Therefore, the result is said to be ambiguous relative to which source it originated from.
      See Also:
    • anyOf

      @SafeVarargs public static <T> Single<T> anyOf(Single<? extends T>... singles)
      Creates a new Single that terminates with the result (either success or error) of whichever amongst the passed singles that terminates first. Therefore, the result is said to be ambiguous relative to which source it originated from. After the first source terminates, only the non-terminated sources will be cancelled.

      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 individual Singles
      Parameters:
      singles - Singles to subscribe to and race to propagate to the return value.
      Returns:
      A new Single that terminates with the result (either success or error) of whichever amongst the passed singles that terminates first.
      See Also:
    • anyOf

      public static <T> Single<T> anyOf(Iterable<Single<? extends T>> singles)
      Creates a new Single that terminates with the result (either success or error) of whichever amongst the passed singles that terminates first. Therefore, the result is said to be ambiguous relative to which source it originated from. After the first source terminates, only the non-terminated sources will be cancelled.

      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 individual Singles
      Parameters:
      singles - Singles to subscribe to and race to propagate to the return value.
      Returns:
      A new Single that terminates with the result (either success or error) of whichever amongst the passed singles that terminates first.
      See Also:
    • zip

      public static <T1, T2, R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, BiFunction<? super T1,? super T2,? extends R> zipper)
      Create a new Single that emits the results of a specified zipper BiFunction to items emitted by s1 and s2.

      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 first Single.
      T2 - The type for the second Single.
      R - The result type of the zipper.
      Parameters:
      s1 - The first Single to zip.
      s2 - The second Single to zip.
      zipper - Used to combine the completed results for each item from singles.
      Returns:
      a new Single that emits the results of a specified zipper BiFunction to items emitted by s1 and s2.
      See Also:
    • zipDelayError

      public static <T1, T2, R> Single<R> zipDelayError(Single<? extends T1> s1, Single<? extends T2> s2, BiFunction<? super T1,? super T2,? extends R> zipper)
      Create a new Single that emits the results of a specified zipper BiFunction to items emitted by s1 and s2. If any of the Singles terminate with an error, the returned Single will wait for termination till all the other Singles have been subscribed and terminated, and then terminate with the first error.

      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 first Single.
      T2 - The type for the second Single.
      R - The result type of the zipper.
      Parameters:
      s1 - The first Single to zip.
      s2 - The second Single to zip.
      zipper - Used to combine the completed results for each item from singles.
      Returns:
      a new Single that emits the results of a specified zipper BiFunction to items emitted by s1 and s2.
      See Also:
    • 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 new Single that emits the results of a specified zipper Function3 to items emitted by s1, s2, and s3.

      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 first Single.
      T2 - The type for the second Single.
      T3 - The type for the third Single.
      R - The result type of the zipper.
      Parameters:
      s1 - The first Single to zip.
      s2 - The second Single to zip.
      s3 - The third Single to zip.
      zipper - Used to combine the completed results for each item from singles.
      Returns:
      a new Single that emits the results of a specified zipper Function3 to items emitted by s1, s2, and s3.
      See Also:
    • zipDelayError

      public static <T1, T2, T3, R> Single<R> zipDelayError(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Function3<? super T1,? super T2,? super T3,? extends R> zipper)
      Create a new Single that emits the results of a specified zipper Function3 to items emitted by s1, s2, and s3. If any of the Singles terminate with an error, the returned Single will wait for termination till all the other Singles have been subscribed and terminated, and then terminate with the first error.

      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 first Single.
      T2 - The type for the second Single.
      T3 - The type for the third Single.
      R - The result type of the zipper.
      Parameters:
      s1 - The first Single to zip.
      s2 - The second Single to zip.
      s3 - The third Single to zip.
      zipper - Used to combine the completed results for each item from singles.
      Returns:
      a new Single that emits the results of a specified zipper Function3 to items emitted by s1, s2, and s3.
      See Also:
    • 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 new Single that emits the results of a specified zipper Function4 to items emitted by s1, s2, s3, and s4.

      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 first Single.
      T2 - The type for the second Single.
      T3 - The type for the third Single.
      T4 - The type for the fourth Single.
      R - The result type of the zipper.
      Parameters:
      s1 - The first Single to zip.
      s2 - The second Single to zip.
      s3 - The third Single to zip.
      s4 - The fourth Single to zip.
      zipper - Used to combine the completed results for each item from singles.
      Returns:
      a new Single that emits the results of a specified zipper Function4 to items emitted by s1, s2, s3, and s4.
      See Also:
    • zipDelayError

      public static <T1, T2, T3, T4, R> Single<R> zipDelayError(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 new Single that emits the results of a specified zipper Function4 to items emitted by s1, s2, s3, and s4. If any of the Singles terminate with an error, the returned Single will wait for termination till all the other Singles have been subscribed and terminated, and then terminate with the first error.

      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 first Single.
      T2 - The type for the second Single.
      T3 - The type for the third Single.
      T4 - The type for the fourth Single.
      R - The result type of the zipper.
      Parameters:
      s1 - The first Single to zip.
      s2 - The second Single to zip.
      s3 - The third Single to zip.
      s4 - The fourth Single to zip.
      zipper - Used to combine the completed results for each item from singles.
      Returns:
      a new Single that emits the results of a specified zipper Function4 to items emitted by s1, s2, s3, and s4.
      See Also:
    • zip

      public static <R> Single<R> zip(Function<? super Object[],? extends R> zipper, Single<?>... singles)
      Create a new Single that emits the results of a specified zipper Function to items emitted by singles.

      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 from singles.
      singles - The collection of Singles that when complete provides the results to "zip" (aka combine) together.
      Returns:
      a new Single that emits the results of a specified zipper Function to items emitted by singles.
      See Also:
    • zipDelayError

      public static <R> Single<R> zipDelayError(Function<? super Object[],? extends R> zipper, Single<?>... singles)
      Create a new Single that emits the results of a specified zipper Function to items emitted by singles. If any of the Singles terminate with an error, the returned Single will wait for termination till all the other Singles have been subscribed and terminated, and then terminate with the first error.

      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 from singles.
      singles - The collection of Singles that when complete provides the results to "zip" (aka combine) together.
      Returns:
      a new Single that emits the results of a specified zipper Function to items emitted by singles.
      See Also: