Class Completable

    • Constructor Detail

      • Completable

        public Completable()
    • Method Detail

      • ambArray

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        @SafeVarargs
        public static @NonNull Completable ambArray​(@NonNull
                                                    @NonNull CompletableSource... sources)
        Returns a Completable which terminates as soon as one of the source Completables terminates (normally or with an error) and disposes all other Completables.

        Scheduler:
        ambArray does not operate by default on a particular Scheduler.
        Parameters:
        sources - the array of source Completables. A subscription to each source will occur in the same order as in this array.
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if sources is null
      • amb

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static @NonNull Completable amb​(@NonNull
                                               @NonNull java.lang.Iterable<? extends CompletableSource> sources)
        Returns a Completable which terminates as soon as one of the source Completables in the Iterable sequence terminates (normally or with an error) and disposes all other Completables.

        Scheduler:
        amb does not operate by default on a particular Scheduler.
        Parameters:
        sources - the Iterable of source Completables. A subscription to each source will occur in the same order as in this Iterable.
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if sources is null
      • concatArrayDelayError

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        @SafeVarargs
        public static @NonNull Completable concatArrayDelayError​(@NonNull
                                                                 @NonNull CompletableSource... sources)
        Returns a Completable which completes only when all sources complete, one after another.

        Scheduler:
        concatArrayDelayError does not operate by default on a particular Scheduler.
        Parameters:
        sources - the sources to concatenate
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        Since:
        3.0.0
      • concat

        @CheckReturnValue
        @SchedulerSupport("none")
        @BackpressureSupport(FULL)
        @NonNull
        public static @NonNull Completable concat​(@NonNull
                                                  @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources)
        Returns a Completable which completes only when all sources complete, one after another.

        Backpressure:
        The returned Completable honors the backpressure of the downstream consumer and expects the other Publisher to honor it as well.
        Scheduler:
        concat does not operate by default on a particular Scheduler.
        Parameters:
        sources - the sources to concatenate
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if sources is null
      • concat

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        @BackpressureSupport(FULL)
        public static @NonNull Completable concat​(@NonNull
                                                  @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources,
                                                  int prefetch)
        Returns a Completable which completes only when all sources complete, one after another.

        Backpressure:
        The returned Completable honors the backpressure of the downstream consumer and expects the other Publisher to honor it as well.
        Scheduler:
        concat does not operate by default on a particular Scheduler.
        Parameters:
        sources - the sources to concatenate
        prefetch - the number of sources to prefetch from the sources
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        java.lang.IllegalArgumentException - if prefetch is non-positive
      • concatDelayError

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static @NonNull Completable concatDelayError​(@NonNull
                                                            @NonNull java.lang.Iterable<? extends CompletableSource> sources)
        Returns a Completable which completes only when all sources complete, one after another.

        Scheduler:
        concatDelayError does not operate by default on a particular Scheduler.
        Parameters:
        sources - the sources to concatenate
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        Since:
        3.0.0
      • concatDelayError

        @CheckReturnValue
        @SchedulerSupport("none")
        @BackpressureSupport(FULL)
        @NonNull
        public static @NonNull Completable concatDelayError​(@NonNull
                                                            @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources)
        Returns a Completable which completes only when all sources complete, one after another.

        Backpressure:
        The returned Completable honors the backpressure of the downstream consumer and expects the other Publisher to honor it as well.
        Scheduler:
        concatDelayError does not operate by default on a particular Scheduler.
        Parameters:
        sources - the sources to concatenate
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        Since:
        3.0.0
      • concatDelayError

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        @BackpressureSupport(FULL)
        public static @NonNull Completable concatDelayError​(@NonNull
                                                            @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources,
                                                            int prefetch)
        Returns a Completable which completes only when all sources complete, one after another.

        Backpressure:
        The returned Completable honors the backpressure of the downstream consumer and expects the other Publisher to honor it as well.
        Scheduler:
        concatDelayError does not operate by default on a particular Scheduler.
        Parameters:
        sources - the sources to concatenate
        prefetch - the number of sources to prefetch from the sources
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        java.lang.IllegalArgumentException - if prefetch is non-positive
        Since:
        3.0.0
      • create

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static @NonNull Completable create​(@NonNull
                                                  @NonNull CompletableOnSubscribe source)
        Provides an API (via a cold Completable) that bridges the reactive world with the callback-style world.

        Example:

        
         Completable.create(emitter -> {
             Callback listener = new Callback() {
                 @Override
                 public void onEvent(Event e) {
                     emitter.onComplete();
                 }
        
                 @Override
                 public void onFailure(Exception e) {
                     emitter.onError(e);
                 }
             };
        
             AutoCloseable c = api.someMethod(listener);
        
             emitter.setCancellable(c::close);
        
         });
         

        Whenever a CompletableObserver subscribes to the returned Completable, the provided CompletableOnSubscribe callback is invoked with a fresh instance of a CompletableEmitter that will interact only with that specific CompletableObserver. If this CompletableObserver disposes the flow (making CompletableEmitter.isDisposed() return true), other observers subscribed to the same returned Completable are not affected.

        Scheduler:
        create does not operate by default on a particular Scheduler.
        Parameters:
        source - the emitter that is called when a CompletableObserver subscribes to the returned Completable
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if source is null
        See Also:
        CompletableOnSubscribe, Cancellable
      • unsafeCreate

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static @NonNull Completable unsafeCreate​(@NonNull
                                                        @NonNull CompletableSource onSubscribe)
        Constructs a Completable instance by wrapping the given source callback without any safeguards; you should manage the lifecycle and response to downstream disposal.

        Scheduler:
        unsafeCreate does not operate by default on a particular Scheduler.
        Parameters:
        onSubscribe - the callback which will receive the CompletableObserver instances when the Completable is subscribed to.
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if onSubscribe is null
        java.lang.IllegalArgumentException - if source is a Completable
      • error

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static @NonNull Completable error​(@NonNull
                                                 @NonNull Supplier<? extends @NonNull java.lang.Throwable> supplier)
        Creates a Completable which calls the given error supplier for each subscriber and emits its returned Throwable.

        If the errorSupplier returns null, the downstream CompletableObservers will receive a NullPointerException.

        Scheduler:
        error does not operate by default on a particular Scheduler.
        Parameters:
        supplier - the error supplier, not null
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if supplier is null
      • error

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static @NonNull Completable error​(@NonNull
                                                 @NonNull java.lang.Throwable throwable)
        Creates a Completable instance that emits the given Throwable exception to subscribers.

        Scheduler:
        error does not operate by default on a particular Scheduler.
        Parameters:
        throwable - the Throwable instance to emit, not null
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if throwable is null
      • fromMaybe

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull T> @NonNull Completable fromMaybe​(@NonNull
                                                                  @NonNull MaybeSource<@NonNull T> maybe)
        Returns a Completable instance that when subscribed to, subscribes to the MaybeSource instance and emits an onComplete event if the maybe emits onSuccess/onComplete or forwards any onError events.

        Scheduler:
        fromMaybe does not operate by default on a particular Scheduler.

        History: 2.1.17 - beta

        Type Parameters:
        T - the value type of the MaybeSource element
        Parameters:
        maybe - the MaybeSource instance to subscribe to, not null
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if maybe is null
        Since:
        2.2
      • fromRunnable

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static @NonNull Completable fromRunnable​(@NonNull
                                                        @NonNull java.lang.Runnable run)
        Returns a Completable instance that runs the given Runnable for each CompletableObserver and emits either its unchecked exception or simply completes.

        If the code to be wrapped needs to throw a checked or more broader Throwable exception, that exception has to be converted to an unchecked exception by the wrapped code itself. Alternatively, use the fromAction(Action) method which allows the wrapped code to throw any Throwable exception and will signal it to observers as-is.

        Scheduler:
        fromRunnable does not operate by default on a particular Scheduler.
        Error handling:
        If the Runnable throws an exception, the respective Throwable is delivered to the downstream via CompletableObserver.onError(Throwable), except when the downstream has disposed this Completable source. In this latter case, the Throwable is delivered to the global error handler via RxJavaPlugins.onError(Throwable) as an UndeliverableException.
        Parameters:
        run - the Runnable to run for each CompletableObserver
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if run is null
        See Also:
        fromAction(Action)
      • fromPublisher

        @CheckReturnValue
        @NonNull
        @BackpressureSupport(UNBOUNDED_IN)
        @SchedulerSupport("none")
        public static <@NonNull T> @NonNull Completable fromPublisher​(@NonNull
                                                                      @NonNull org.reactivestreams.Publisher<@NonNull T> publisher)
        Returns a Completable instance that subscribes to the given Publisher, ignores all values and emits only the terminal event.

        The Publisher must follow the Reactive-Streams specification. Violating the specification may result in undefined behavior.

        If possible, use create(CompletableOnSubscribe) to create a source-like Completable instead.

        Note that even though Publisher appears to be a functional interface, it is not recommended to implement it through a lambda as the specification requires state management that is not achievable with a stateless lambda.

        Backpressure:
        The returned Completable honors the backpressure of the downstream consumer and expects the other Publisher to honor it as well.
        Scheduler:
        fromPublisher does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the type of the Publisher
        Parameters:
        publisher - the Publisher instance to subscribe to, not null
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if publisher is null
        See Also:
        create(CompletableOnSubscribe)
      • fromSingle

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull T> @NonNull Completable fromSingle​(@NonNull
                                                                   @NonNull SingleSource<@NonNull T> single)
        Returns a Completable instance that when subscribed to, subscribes to the SingleSource instance and emits a completion event if the single emits onSuccess or forwards any onError events.

        Scheduler:
        fromSingle does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type of the SingleSource
        Parameters:
        single - the SingleSource instance to subscribe to, not null
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if single is null
      • mergeArray

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        @SafeVarargs
        public static @NonNull Completable mergeArray​(@NonNull
                                                      @NonNull CompletableSource... sources)
        Returns a Completable instance that subscribes to all sources at once and completes only when all source CompletableSources complete or one of them emits an error.

        Scheduler:
        mergeArray does not operate by default on a particular Scheduler.
        Error handling:
        If any of the source CompletableSources signal a Throwable via onError, the resulting Completable terminates with that Throwable and all other source CompletableSources are disposed. If more than one CompletableSource signals an error, the resulting Completable may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with a CompositeException containing two or more of the various error signals. Throwables that didn't make into the composite will be sent (individually) to the global error handler via RxJavaPlugins.onError(Throwable) method as UndeliverableException errors. Similarly, Throwables signaled by source(s) after the returned Completable has been disposed or terminated with a (composite) error will be sent to the same global error handler. Use mergeArrayDelayError(CompletableSource...) to merge sources and terminate only when all source CompletableSources have completed or failed with an error.
        Parameters:
        sources - the array of CompletableSources.
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        See Also:
        mergeArrayDelayError(CompletableSource...)
      • merge

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static @NonNull Completable merge​(@NonNull
                                                 @NonNull java.lang.Iterable<? extends CompletableSource> sources)
        Returns a Completable instance that subscribes to all sources at once and completes only when all source CompletableSources complete or one of them emits an error.

        Scheduler:
        merge does not operate by default on a particular Scheduler.
        Error handling:
        If any of the source CompletableSources signal a Throwable via onError, the resulting Completable terminates with that Throwable and all other source CompletableSources are disposed. If more than one CompletableSource signals an error, the resulting Completable may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with a CompositeException containing two or more of the various error signals. Throwables that didn't make into the composite will be sent (individually) to the global error handler via RxJavaPlugins.onError(Throwable) method as UndeliverableException errors. Similarly, Throwables signaled by source(s) after the returned Completable has been disposed or terminated with a (composite) error will be sent to the same global error handler. Use mergeDelayError(Iterable) to merge sources and terminate only when all source CompletableSources have completed or failed with an error.
        Parameters:
        sources - the Iterable sequence of CompletableSources.
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        See Also:
        mergeDelayError(Iterable)
      • merge

        @CheckReturnValue
        @SchedulerSupport("none")
        @BackpressureSupport(UNBOUNDED_IN)
        @NonNull
        public static @NonNull Completable merge​(@NonNull
                                                 @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources)
        Returns a Completable instance that subscribes to all sources at once and completes only when all source CompletableSources complete or one of them emits an error.

        Backpressure:
        The operator consumes the given Publisher in an unbounded manner (requesting Long.MAX_VALUE upfront).
        Scheduler:
        merge does not operate by default on a particular Scheduler.
        Error handling:
        If any of the source CompletableSources signal a Throwable via onError, the resulting Completable terminates with that Throwable and all other source CompletableSources are disposed. If more than one CompletableSource signals an error, the resulting Completable may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with a CompositeException containing two or more of the various error signals. Throwables that didn't make into the composite will be sent (individually) to the global error handler via RxJavaPlugins.onError(Throwable) method as UndeliverableException errors. Similarly, Throwables signaled by source(s) after the returned Completable has been disposed or terminated with a (composite) error will be sent to the same global error handler. Use mergeDelayError(Publisher) to merge sources and terminate only when all source CompletableSources have completed or failed with an error.
        Parameters:
        sources - the Publisher sequence of CompletableSources.
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        See Also:
        mergeDelayError(Publisher)
      • merge

        @CheckReturnValue
        @SchedulerSupport("none")
        @BackpressureSupport(FULL)
        @NonNull
        public static @NonNull Completable merge​(@NonNull
                                                 @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources,
                                                 int maxConcurrency)
        Returns a Completable instance that keeps subscriptions to a limited number of sources at once and completes only when all source CompletableSources complete or one of them emits an error.

        Backpressure:
        The operator consumes the given Publisher in a bounded manner, requesting maxConcurrency items first, then keeps requesting as many more as the inner CompletableSources terminate.
        Scheduler:
        merge does not operate by default on a particular Scheduler.
        Error handling:
        If any of the source CompletableSources signal a Throwable via onError, the resulting Completable terminates with that Throwable and all other source CompletableSources are disposed. If more than one CompletableSource signals an error, the resulting Completable may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with a CompositeException containing two or more of the various error signals. Throwables that didn't make into the composite will be sent (individually) to the global error handler via RxJavaPlugins.onError(Throwable) method as UndeliverableException errors. Similarly, Throwables signaled by source(s) after the returned Completable has been disposed or terminated with a (composite) error will be sent to the same global error handler. Use mergeDelayError(Publisher, int) to merge sources and terminate only when all source CompletableSources have completed or failed with an error.
        Parameters:
        sources - the Publisher sequence of CompletableSources.
        maxConcurrency - the maximum number of concurrent subscriptions
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        java.lang.IllegalArgumentException - if maxConcurrency is less than 1
        See Also:
        mergeDelayError(Publisher, int)
      • merge0

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        @BackpressureSupport(FULL)
        private static @NonNull Completable merge0​(@NonNull
                                                   @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources,
                                                   int maxConcurrency,
                                                   boolean delayErrors)
        Returns a Completable instance that keeps subscriptions to a limited number of CompletableSources at once and completes only when all source CompletableSources terminate in one way or another, combining any exceptions signaled by either the source Publisher or the inner CompletableSource instances.
        Backpressure:
        The operator consumes the given Publisher in a bounded manner, requesting maxConcurrency items first, then keeps requesting as many more as the inner CompletableSources terminate.
        Scheduler:
        merge0 does not operate by default on a particular Scheduler.
        Parameters:
        sources - the Publisher sequence of CompletableSources.
        maxConcurrency - the maximum number of concurrent subscriptions
        delayErrors - delay all errors from the main source and from the inner CompletableSources?
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        java.lang.IllegalArgumentException - if maxConcurrency is less than 1
      • mergeArrayDelayError

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        @SafeVarargs
        public static @NonNull Completable mergeArrayDelayError​(@NonNull
                                                                @NonNull CompletableSource... sources)
        Returns a Completable that subscribes to all CompletableSources in the source array and delays any error emitted by any of the inner CompletableSources until all of them terminate in a way or another.

        Scheduler:
        mergeArrayDelayError does not operate by default on a particular Scheduler.
        Parameters:
        sources - the array of CompletableSources
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if sources is null
      • mergeDelayError

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static @NonNull Completable mergeDelayError​(@NonNull
                                                           @NonNull java.lang.Iterable<? extends CompletableSource> sources)
        Returns a Completable that subscribes to all CompletableSources in the source sequence and delays any error emitted by any of the inner CompletableSources until all of them terminate in a way or another.

        Scheduler:
        mergeDelayError does not operate by default on a particular Scheduler.
        Parameters:
        sources - the sequence of CompletableSources
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if sources is null
      • mergeDelayError

        @CheckReturnValue
        @SchedulerSupport("none")
        @BackpressureSupport(UNBOUNDED_IN)
        @NonNull
        public static @NonNull Completable mergeDelayError​(@NonNull
                                                           @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources)
        Returns a Completable that subscribes to all CompletableSources in the source sequence and delays any error emitted by either the sources Publisher or any of the inner CompletableSources until all of them terminate in a way or another.

        Backpressure:
        The operator consumes the Publisher in an unbounded manner (requesting Long.MAX_VALUE from it).
        Scheduler:
        mergeDelayError does not operate by default on a particular Scheduler.
        Parameters:
        sources - the sequence of CompletableSources
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if sources is null
      • mergeDelayError

        @CheckReturnValue
        @SchedulerSupport("none")
        @BackpressureSupport(FULL)
        @NonNull
        public static @NonNull Completable mergeDelayError​(@NonNull
                                                           @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources,
                                                           int maxConcurrency)
        Returns a Completable that subscribes to a limited number of inner CompletableSources at once in the source sequence and delays any error emitted by either the sources Publisher or any of the inner CompletableSources until all of them terminate in a way or another.

        Backpressure:
        The operator requests maxConcurrency items from the Publisher upfront and keeps requesting as many more as many inner CompletableSources terminate.
        Scheduler:
        mergeDelayError does not operate by default on a particular Scheduler.
        Parameters:
        sources - the sequence of CompletableSources
        maxConcurrency - the maximum number of concurrent subscriptions to have at a time to the inner CompletableSources
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        java.lang.IllegalArgumentException - if maxConcurrency is non-positive
      • timer

        @CheckReturnValue
        @SchedulerSupport("io.reactivex:computation")
        @NonNull
        public static @NonNull Completable timer​(long delay,
                                                 @NonNull
                                                 @NonNull java.util.concurrent.TimeUnit unit)
        Returns a Completable instance that fires its onComplete event after the given delay elapsed.

        Scheduler:
        timer does operate by default on the computation Scheduler.
        Parameters:
        delay - the delay time
        unit - the delay unit
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if unit is null
      • timer

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("custom")
        public static @NonNull Completable timer​(long delay,
                                                 @NonNull
                                                 @NonNull java.util.concurrent.TimeUnit unit,
                                                 @NonNull
                                                 @NonNull Scheduler scheduler)
        Returns a Completable instance that fires its onComplete event after the given delay elapsed by using the supplied Scheduler.

        Scheduler:
        timer operates on the Scheduler you specify.
        Parameters:
        delay - the delay time
        unit - the delay unit
        scheduler - the Scheduler where to emit the onComplete event
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if unit or scheduler is null
      • toNpe

        private static java.lang.NullPointerException toNpe​(java.lang.Throwable ex)
        Creates a NullPointerException instance and sets the given Throwable as its initial cause.
        Parameters:
        ex - the Throwable instance to use as cause, not null (not verified)
        Returns:
        the new NullPointerException
      • switchOnNextDelayError

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        @BackpressureSupport(UNBOUNDED_IN)
        public static @NonNull Completable switchOnNextDelayError​(@NonNull
                                                                  @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources)
        Switches between CompletableSources emitted by the source Publisher whenever a new CompletableSource is emitted, disposing the previously running CompletableSource, exposing the setup as a Completable sequence and delaying all errors from all of them until all terminate.

        Backpressure:
        The sources Publisher is consumed in an unbounded manner (requesting Long.MAX_VALUE).
        Scheduler:
        switchOnNextDelayError does not operate by default on a particular Scheduler.
        Error handling:
        The returned Completable collects all errors emitted by either the sources Publisher or any inner CompletableSource and emits them as a CompositeException when all sources terminate. If only one source ever failed, its error is emitted as-is at the end.
        Parameters:
        sources - the Publisher sequence of inner CompletableSources to switch between
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        Since:
        3.0.0
        See Also:
        switchOnNext(Publisher), ReactiveX operators documentation: Switch
      • using

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull R> @NonNull Completable using​(@NonNull
                                                              @NonNull Supplier<@NonNull R> resourceSupplier,
                                                              @NonNull
                                                              @NonNull Function<? super @NonNull R,​? extends CompletableSource> sourceSupplier,
                                                              @NonNull
                                                              @NonNull Consumer<? super @NonNull R> resourceCleanup,
                                                              boolean eager)
        Returns a Completable instance which manages a resource along with a custom CompletableSource instance while the subscription is active and performs eager or lazy resource disposition.

        If this overload performs a lazy disposal after the terminal event is emitted. The exceptions thrown at this time will be delivered to the global RxJavaPlugins.onError(Throwable) handler only.

        Scheduler:
        using does not operate by default on a particular Scheduler.
        Type Parameters:
        R - the resource type
        Parameters:
        resourceSupplier - the Supplier that returns a resource to be managed
        sourceSupplier - the Function that given a resource returns a non-null CompletableSource instance that will be subscribed to
        resourceCleanup - the Consumer that disposes the resource created by the resource supplier
        eager - If true then resource disposal will happen either on a dispose() call before the upstream is disposed or just before the emission of a terminal event (onComplete or onError). If false the resource disposal will happen either on a dispose() call after the upstream is disposed or just after the emission of a terminal event (onComplete or onError).
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if resourceSupplier, sourceSupplier or resourceCleanup is null
      • ambWith

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final @NonNull Completable ambWith​(@NonNull
                                                  @NonNull CompletableSource other)
        Returns a Completable that emits the a terminated event of either this Completable or the other CompletableSource, whichever fires first.

        Scheduler:
        ambWith does not operate by default on a particular Scheduler.
        Parameters:
        other - the other CompletableSource, not null. A subscription to this provided source will occur after subscribing to the current source.
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if other is null
      • andThen

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final <@NonNull T> @NonNull Observable<T> andThen​(@NonNull
                                                                 @NonNull ObservableSource<@NonNull T> next)
        Returns an Observable which will subscribe to this Completable and once that is completed then will subscribe to the next ObservableSource. An error event from this Completable will be propagated to the downstream observer and will result in skipping the subscription to the next ObservableSource.

        Scheduler:
        andThen does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type of the next ObservableSource
        Parameters:
        next - the ObservableSource to subscribe after this Completable is completed, not null
        Returns:
        the new Observable that composes this Completable and the next ObservableSource
        Throws:
        java.lang.NullPointerException - if next is null
      • andThen

        @CheckReturnValue
        @NonNull
        @BackpressureSupport(FULL)
        @SchedulerSupport("none")
        public final <@NonNull T> @NonNull Flowable<T> andThen​(@NonNull
                                                               @NonNull org.reactivestreams.Publisher<@NonNull T> next)
        Returns a Flowable which will subscribe to this Completable and once that is completed then will subscribe to the next Publisher. An error event from this Completable will be propagated to the downstream subscriber and will result in skipping the subscription to the next Publisher.

        Backpressure:
        The returned Flowable honors the backpressure of the downstream consumer and expects the other Publisher to honor it as well.
        Scheduler:
        andThen does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type of the next Publisher
        Parameters:
        next - the Publisher to subscribe after this Completable is completed, not null
        Returns:
        the new Flowable that composes this Completable and the next Publisher
        Throws:
        java.lang.NullPointerException - if next is null
      • andThen

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final <@NonNull T> @NonNull Single<T> andThen​(@NonNull
                                                             @NonNull SingleSource<@NonNull T> next)
        Returns a Single which will subscribe to this Completable and once that is completed then will subscribe to the next SingleSource. An error event from this Completable will be propagated to the downstream observer and will result in skipping the subscription to the next SingleSource.

        Scheduler:
        andThen does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type of the next SingleSource
        Parameters:
        next - the SingleSource to subscribe after this Completable is completed, not null
        Returns:
        the new Single that composes this Completable and the next SingleSource
        Throws:
        java.lang.NullPointerException - if next is null
      • andThen

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final <@NonNull T> @NonNull Maybe<T> andThen​(@NonNull
                                                            @NonNull MaybeSource<@NonNull T> next)
        Returns a Maybe which will subscribe to this Completable and once that is completed then will subscribe to the next MaybeSource. An error event from this Completable will be propagated to the downstream observer and will result in skipping the subscription to the next MaybeSource.

        Scheduler:
        andThen does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type of the next MaybeSource
        Parameters:
        next - the MaybeSource to subscribe after this Completable is completed, not null
        Returns:
        the new Maybe that composes this Completable and the next MaybeSource
        Throws:
        java.lang.NullPointerException - if next is null
      • blockingAwait

        @SchedulerSupport("none")
        public final void blockingAwait()
        Subscribes to and awaits the termination of this Completable instance in a blocking manner and rethrows any exception emitted.

        Scheduler:
        blockingAwait does not operate by default on a particular Scheduler.
        Error handling:
        If the source signals an error, the operator wraps a checked Exception into RuntimeException and throws that. Otherwise, RuntimeExceptions and Errors are rethrown as they are.
        Throws:
        java.lang.RuntimeException - wrapping an InterruptedException if the current thread is interrupted
      • blockingAwait

        @CheckReturnValue
        @SchedulerSupport("none")
        public final boolean blockingAwait​(long timeout,
                                           @NonNull
                                           @NonNull java.util.concurrent.TimeUnit unit)
        Subscribes to and awaits the termination of this Completable instance in a blocking manner with a specific timeout and rethrows any exception emitted within the timeout window.

        Scheduler:
        blockingAwait does not operate by default on a particular Scheduler.
        Error handling:
        If the source signals an error, the operator wraps a checked Exception into RuntimeException and throws that. Otherwise, RuntimeExceptions and Errors are rethrown as they are.
        Parameters:
        timeout - the timeout value
        unit - the timeout unit
        Returns:
        true if the this Completable instance completed normally within the time limit, false if the timeout elapsed before this Completable terminated.
        Throws:
        java.lang.RuntimeException - wrapping an InterruptedException if the current thread is interrupted
        java.lang.NullPointerException - if unit is null
      • blockingSubscribe

        @SchedulerSupport("none")
        public final void blockingSubscribe()
        Subscribes to the current Completable and blocks the current thread until it terminates.

        Scheduler:
        blockingSubscribe does not operate by default on a particular Scheduler.
        Error handling:
        If the current Completable signals an error, the Throwable is routed to the global error handler via RxJavaPlugins.onError(Throwable). If the current thread is interrupted, an InterruptedException is routed to the same global error handler.
        Since:
        3.0.0
        See Also:
        blockingSubscribe(Action), blockingSubscribe(Action, Consumer)
      • blockingSubscribe

        @SchedulerSupport("none")
        public final void blockingSubscribe​(@NonNull
                                            @NonNull Action onComplete)
        Subscribes to the current Completable and calls given onComplete callback on the current thread when it completes normally.

        Scheduler:
        blockingSubscribe does not operate by default on a particular Scheduler.
        Error handling:
        If either the current Completable signals an error or onComplete throws, the respective Throwable is routed to the global error handler via RxJavaPlugins.onError(Throwable). If the current thread is interrupted, an InterruptedException is routed to the same global error handler.
        Parameters:
        onComplete - the Action to call if the current Completable completes normally
        Throws:
        java.lang.NullPointerException - if onComplete is null
        Since:
        3.0.0
        See Also:
        blockingSubscribe(Action, Consumer)
      • blockingSubscribe

        @SchedulerSupport("none")
        public final void blockingSubscribe​(@NonNull
                                            @NonNull Action onComplete,
                                            @NonNull
                                            @NonNull Consumer<? super java.lang.Throwable> onError)
        Subscribes to the current Completable and calls the appropriate callback on the current thread when it terminates.

        Scheduler:
        blockingSubscribe does not operate by default on a particular Scheduler.
        Error handling:
        If either onComplete or onError throw, the Throwable is routed to the global error handler via RxJavaPlugins.onError(Throwable). If the current thread is interrupted, the onError consumer is called with an InterruptedException.
        Parameters:
        onComplete - the Action to call if the current Completable completes normally
        onError - the Consumer to call if the current Completable signals an error
        Throws:
        java.lang.NullPointerException - if onComplete or onError is null
        Since:
        3.0.0
      • blockingSubscribe

        @SchedulerSupport("none")
        public final void blockingSubscribe​(@NonNull
                                            @NonNull CompletableObserver observer)
        Subscribes to the current Completable and calls the appropriate CompletableObserver method on the current thread.

        Scheduler:
        blockingSubscribe does not operate by default on a particular Scheduler.
        Error handling:
        An onError signal is delivered to the CompletableObserver.onError(Throwable) method. If any of the CompletableObserver's methods throw, the RuntimeException is propagated to the caller of this method. If the current thread is interrupted, an InterruptedException is delivered to observer.onError.
        Parameters:
        observer - the CompletableObserver to call methods on the current thread
        Throws:
        java.lang.NullPointerException - if observer is null
        Since:
        3.0.0
      • cache

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Completable cache()
        Subscribes to this Completable only once, when the first CompletableObserver subscribes to the result Completable, caches its terminal event and relays/replays it to observers.

        Note that this operator doesn't allow disposing the connection of the upstream source.

        Scheduler:
        cache does not operate by default on a particular Scheduler.

        History: 2.0.4 - experimental

        Returns:
        the new Completable instance
        Since:
        2.1
      • delay

        @CheckReturnValue
        @SchedulerSupport("io.reactivex:computation")
        @NonNull
        public final @NonNull Completable delay​(long time,
                                                @NonNull
                                                @NonNull java.util.concurrent.TimeUnit unit)
        Returns a Completable which delays the emission of the completion event by the given time.

        Scheduler:
        delay does operate by default on the computation Scheduler.
        Parameters:
        time - the delay time
        unit - the delay unit
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if unit is null
      • delay

        @CheckReturnValue
        @SchedulerSupport("custom")
        @NonNull
        public final @NonNull Completable delay​(long time,
                                                @NonNull
                                                @NonNull java.util.concurrent.TimeUnit unit,
                                                @NonNull
                                                @NonNull Scheduler scheduler)
        Returns a Completable which delays the emission of the completion event by the given time while running on the specified Scheduler.

        Scheduler:
        delay operates on the Scheduler you specify.
        Parameters:
        time - the delay time
        unit - the delay unit
        scheduler - the Scheduler to run the delayed completion on
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if unit or scheduler is null
      • delay

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("custom")
        public final @NonNull Completable delay​(long time,
                                                @NonNull
                                                @NonNull java.util.concurrent.TimeUnit unit,
                                                @NonNull
                                                @NonNull Scheduler scheduler,
                                                boolean delayError)
        Returns a Completable which delays the emission of the completion event, and optionally the error as well, by the given time while running on the specified Scheduler.

        Scheduler:
        delay operates on the Scheduler you specify.
        Parameters:
        time - the delay time
        unit - the delay unit
        scheduler - the Scheduler to run the delayed completion on
        delayError - delay the error emission as well?
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if unit or scheduler is null
      • delaySubscription

        @CheckReturnValue
        @SchedulerSupport("io.reactivex:computation")
        @NonNull
        public final @NonNull Completable delaySubscription​(long time,
                                                            @NonNull
                                                            @NonNull java.util.concurrent.TimeUnit unit)
        Returns a Completable that delays the subscription to the upstream by a given amount of time.

        Scheduler:
        This version of delaySubscription operates by default on the computation Scheduler.

        History: 2.2.3 - experimental

        Parameters:
        time - the time to delay the subscription
        unit - the time unit of delay
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if unit is null
        Since:
        3.0.0
        See Also:
        ReactiveX operators documentation: Delay
      • delaySubscription

        @CheckReturnValue
        @SchedulerSupport("custom")
        @NonNull
        public final @NonNull Completable delaySubscription​(long time,
                                                            @NonNull
                                                            @NonNull java.util.concurrent.TimeUnit unit,
                                                            @NonNull
                                                            @NonNull Scheduler scheduler)
        Returns a Completable that delays the subscription to the upstream by a given amount of time, both waiting and subscribing on a given Scheduler.

        Scheduler:
        You specify which Scheduler this operator will use.

        History: 2.2.3 - experimental

        Parameters:
        time - the time to delay the subscription
        unit - the time unit of delay
        scheduler - the Scheduler on which the waiting and subscription will happen
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if unit or scheduler is null
        Since:
        3.0.0
        See Also:
        ReactiveX operators documentation: Delay
      • doOnEvent

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final @NonNull Completable doOnEvent​(@NonNull
                                                    @NonNull Consumer<? super java.lang.Throwable> onEvent)
        Returns a Completable which calls the given onEvent Consumer with the Throwable for an onError or null for an onComplete signal from this Completable before delivering the signal to the downstream.

        Scheduler:
        doOnEvent does not operate by default on a particular Scheduler.
        Parameters:
        onEvent - the event Consumer that receives null for upstream completion or a Throwable if the upstream signaled an error
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if onEvent is null
      • doOnLifecycle

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        private @NonNull Completable doOnLifecycle​(Consumer<? super Disposable> onSubscribe,
                                                   Consumer<? super java.lang.Throwable> onError,
                                                   Action onComplete,
                                                   Action onTerminate,
                                                   Action onAfterTerminate,
                                                   Action onDispose)
        Returns a Completable instance that calls the various callbacks upon the specific lifecycle events.
        Scheduler:
        doOnLifecycle does not operate by default on a particular Scheduler.
        Parameters:
        onSubscribe - the Consumer called when a CompletableObserver subscribes.
        onError - the Consumer called when this emits an onError event
        onComplete - the Action called just before when the current Completable completes normally
        onTerminate - the Action called just before this Completable terminates
        onAfterTerminate - the Action called after this Completable completes normally
        onDispose - the Action called when the downstream disposes the subscription
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if onSubscribe, onError, onComplete onTerminate, onAfterTerminate or onDispose is null
      • doOnTerminate

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Completable doOnTerminate​(@NonNull
                                                        @NonNull Action onTerminate)
        Returns a Completable instance that calls the given onTerminate Action just before this Completable completes normally or with an exception.

        Scheduler:
        doOnTerminate does not operate by default on a particular Scheduler.
        Parameters:
        onTerminate - the Action to call just before this Completable terminates
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if onTerminate is null
        See Also:
        doFinally(Action)
      • doAfterTerminate

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Completable doAfterTerminate​(@NonNull
                                                           @NonNull Action onAfterTerminate)
        Returns a Completable instance that calls the given onAfterTerminate Action after this Completable completes normally or with an exception.

        Scheduler:
        doAfterTerminate does not operate by default on a particular Scheduler.
        Parameters:
        onAfterTerminate - the Action to call after this Completable terminates
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if onAfterTerminate is null
        See Also:
        doFinally(Action)
      • doFinally

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final @NonNull Completable doFinally​(@NonNull
                                                    @NonNull Action onFinally)
        Calls the specified Action after this Completable signals onError or onComplete or gets disposed by the downstream.

        In case of a race between a terminal event and a dispose call, the provided onFinally action is executed once per subscription.

        Note that the onFinally action is shared between subscriptions and as such should be thread-safe.

        Scheduler:
        doFinally does not operate by default on a particular Scheduler.

        History: 2.0.1 - experimental

        Parameters:
        onFinally - the Action called when this Completable terminates or gets disposed
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if onFinally is null
        Since:
        2.1
      • lift

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final @NonNull Completable lift​(@NonNull
                                               @NonNull CompletableOperator onLift)
        This method requires advanced knowledge about building operators, please consider other standard composition methods first; Returns a Completable which, when subscribed to, invokes the apply(CompletableObserver) method of the provided CompletableOperator for each individual downstream Completable and allows the insertion of a custom operator by accessing the downstream's CompletableObserver during this subscription phase and providing a new CompletableObserver, containing the custom operator's intended business logic, that will be used in the subscription process going further upstream.

        Generally, such a new CompletableObserver will wrap the downstream's CompletableObserver and forwards the onError and onComplete events from the upstream directly or according to the emission pattern the custom operator's business logic requires. In addition, such operator can intercept the flow control calls of dispose and isDisposed that would have traveled upstream and perform additional actions depending on the same business logic requirements.

        Example:

        
         // Step 1: Create the consumer type that will be returned by the CompletableOperator.apply():
         
         public final class CustomCompletableObserver implements CompletableObserver, Disposable {
        
             // The downstream's CompletableObserver that will receive the onXXX events
             final CompletableObserver downstream;
        
             // The connection to the upstream source that will call this class' onXXX methods
             Disposable upstream;
        
             // The constructor takes the downstream subscriber and usually any other parameters
             public CustomCompletableObserver(CompletableObserver downstream) {
                 this.downstream = downstream;
             }
        
             // In the subscription phase, the upstream sends a Disposable to this class
             // and subsequently this class has to send a Disposable to the downstream.
             // Note that relaying the upstream's Disposable directly is not allowed in RxJava
             @Override
             public void onSubscribe(Disposable d) {
                 if (upstream != null) {
                     d.dispose();
                 } else {
                     upstream = d;
                     downstream.onSubscribe(this);
                 }
             }
        
             // Some operators may handle the upstream's error while others
             // could just forward it to the downstream.
             @Override
             public void onError(Throwable throwable) {
                 downstream.onError(throwable);
             }
        
             // When the upstream completes, usually the downstream should complete as well.
             // In completable, this could also mean doing some side-effects
             @Override
             public void onComplete() {
                 System.out.println("Sequence completed");
                 downstream.onComplete();
             }
        
             // Some operators may use their own resources which should be cleaned up if
             // the downstream disposes the flow before it completed. Operators without
             // resources can simply forward the dispose to the upstream.
             // In some cases, a disposed flag may be set by this method so that other parts
             // of this class may detect the dispose and stop sending events
             // to the downstream.
             @Override
             public void dispose() {
                 upstream.dispose();
             }
        
             // Some operators may simply forward the call to the upstream while others
             // can return the disposed flag set in dispose().
             @Override
             public boolean isDisposed() {
                 return upstream.isDisposed();
             }
         }
        
         // Step 2: Create a class that implements the CompletableOperator interface and
         //         returns the custom consumer type from above in its apply() method.
         //         Such class may define additional parameters to be submitted to
         //         the custom consumer type.
        
         final class CustomCompletableOperator implements CompletableOperator {
             @Override
             public CompletableObserver apply(CompletableObserver upstream) {
                 return new CustomCompletableObserver(upstream);
             }
         }
        
         // Step 3: Apply the custom operator via lift() in a flow by creating an instance of it
         //         or reusing an existing one.
        
         Completable.complete()
         .lift(new CustomCompletableOperator())
         .test()
         .assertResult();
         

        Creating custom operators can be complicated and it is recommended one consults the RxJava wiki: Writing operators page about the tools, requirements, rules, considerations and pitfalls of implementing them.

        Note that implementing custom operators via this lift() method adds slightly more overhead by requiring an additional allocation and indirection per assembled flows. Instead, extending the abstract Completable class and creating a CompletableTransformer with it is recommended.

        Note also that it is not possible to stop the subscription phase in lift() as the apply() method requires a non-null CompletableObserver instance to be returned, which is then unconditionally subscribed to the current Completable. For example, if the operator decided there is no reason to subscribe to the upstream source because of some optimization possibility or a failure to prepare the operator, it still has to return a CompletableObserver that should immediately dispose the upstream's Disposable in its onSubscribe method. Again, using a CompletableTransformer and extending the Completable is a better option as subscribeActual(io.reactivex.rxjava3.core.CompletableObserver) can decide to not subscribe to its upstream after all.

        Scheduler:
        lift does not operate by default on a particular Scheduler, however, the CompletableOperator may use a Scheduler to support its own asynchronous behavior.
        Parameters:
        onLift - the CompletableOperator that receives the downstream's CompletableObserver and should return a CompletableObserver with custom behavior to be used as the consumer for the current Completable.
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if onLift is null
        See Also:
        RxJava wiki: Writing operators, compose(CompletableTransformer)
      • observeOn

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("custom")
        public final @NonNull Completable observeOn​(@NonNull
                                                    @NonNull Scheduler scheduler)
        Returns a Completable which emits the terminal events from the thread of the specified Scheduler.

        Scheduler:
        observeOn operates on a Scheduler you specify.
        Parameters:
        scheduler - the Scheduler to emit terminal events on
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if scheduler is null
      • onErrorComplete

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Completable onErrorComplete()
        Returns a Completable instance that if this Completable emits an error, it will emit an onComplete and swallow the upstream Throwable.

        Scheduler:
        onErrorComplete does not operate by default on a particular Scheduler.
        Returns:
        the new Completable instance
      • onErrorComplete

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final @NonNull Completable onErrorComplete​(@NonNull
                                                          @NonNull Predicate<? super java.lang.Throwable> predicate)
        Returns a Completable instance that if this Completable emits an error and the Predicate returns true, it will emit an onComplete and swallow the Throwable.

        Scheduler:
        onErrorComplete does not operate by default on a particular Scheduler.
        Parameters:
        predicate - the Predicate to call when a Throwable is emitted which should return true if the Throwable should be swallowed and replaced with an onComplete.
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if predicate is null
      • onErrorResumeNext

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final @NonNull Completable onErrorResumeNext​(@NonNull
                                                            @NonNull Function<? super java.lang.Throwable,​? extends CompletableSource> fallbackSupplier)
        Returns a Completable instance that when encounters an error from this Completable, calls the specified mapper Function that returns a CompletableSource instance for it and resumes the execution with it.

        Scheduler:
        onErrorResumeNext does not operate by default on a particular Scheduler.
        Parameters:
        fallbackSupplier - the mapper Function that takes the error and should return a CompletableSource as continuation.
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if fallbackSupplier is null
      • onErrorReturn

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final <@NonNull T> @NonNull Maybe<T> onErrorReturn​(@NonNull
                                                                  @NonNull Function<? super java.lang.Throwable,​? extends @NonNull T> itemSupplier)
        Ends the flow with a success item returned by a function for the Throwable error signaled by the current Completable instead of signaling the error via onError.

        You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.

        Scheduler:
        onErrorReturn does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the item type to return on error
        Parameters:
        itemSupplier - a function that returns a single value that will be emitted as success value the current Completable signals an onError event
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if itemSupplier is null
        Since:
        3.0.0
        See Also:
        ReactiveX operators documentation: Catch
      • onErrorReturnItem

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final <@NonNull T> @NonNull Maybe<T> onErrorReturnItem​(@NonNull
                                                                      @NonNull T item)
        Ends the flow with the given success item when the current Completable fails instead of signaling the error via onError.

        You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.

        Scheduler:
        onErrorReturnItem does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the item type to return on error
        Parameters:
        item - the value that is emitted as onSuccess in case the current Completable signals an onError
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if item is null
        See Also:
        ReactiveX operators documentation: Catch
      • repeat

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Completable repeat​(long times)
        Returns a Completable that subscribes repeatedly at most the given number of times to this Completable.

        Scheduler:
        repeat does not operate by default on a particular Scheduler.
        Parameters:
        times - the number of times the re-subscription should happen
        Returns:
        the new Completable instance
        Throws:
        java.lang.IllegalArgumentException - if times is negative
      • repeatWhen

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Completable repeatWhen​(@NonNull
                                                     @NonNull Function<? super Flowable<java.lang.Object>,​? extends org.reactivestreams.Publisher<?>> handler)
        Returns a Completable instance that repeats when the Publisher returned by the handler Function emits an item or completes when this Publisher emits an onComplete event.

        Scheduler:
        repeatWhen does not operate by default on a particular Scheduler.
        Parameters:
        handler - the Function that transforms the stream of values indicating the completion of this Completable and returns a Publisher that emits items for repeating or completes to indicate the repetition should stop
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if handler is null
      • retry

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Completable retry​(@NonNull
                                                @NonNull BiPredicate<? super java.lang.Integer,​? super java.lang.Throwable> predicate)
        Returns a Completable that retries this Completable in case of an error as long as the predicate returns true.

        Scheduler:
        retry does not operate by default on a particular Scheduler.
        Parameters:
        predicate - the Predicate called when this Completable emits an error with the repeat count and the latest Throwable and should return true to retry.
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if predicate is null
      • retry

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Completable retry​(long times)
        Returns a Completable that when this Completable emits an error, retries at most the given number of times before giving up and emitting the last error.

        Scheduler:
        retry does not operate by default on a particular Scheduler.
        Parameters:
        times - the number of times to resubscribe if the current Completable fails
        Returns:
        the new Completable instance
        Throws:
        java.lang.IllegalArgumentException - if times is negative
      • retry

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Completable retry​(long times,
                                                @NonNull
                                                @NonNull Predicate<? super java.lang.Throwable> predicate)
        Returns a Completable that when this Completable emits an error, retries at most times or until the predicate returns false, whichever happens first and emitting the last error.

        Scheduler:
        retry does not operate by default on a particular Scheduler.

        History: 2.1.8 - experimental

        Parameters:
        times - the number of times to resubscribe if the current Completable fails
        predicate - the Predicate that is called with the latest Throwable and should return true to indicate the returned Completable should resubscribe to this Completable.
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if predicate is null
        java.lang.IllegalArgumentException - if times is negative
        Since:
        2.2
      • retry

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Completable retry​(@NonNull
                                                @NonNull Predicate<? super java.lang.Throwable> predicate)
        Returns a Completable that when this Completable emits an error, calls the given predicate with the latest Throwable to decide whether to resubscribe to the upstream or not.

        Scheduler:
        retry does not operate by default on a particular Scheduler.
        Parameters:
        predicate - the Predicate that is called with the latest Throwable and should return true to indicate the returned Completable should resubscribe to this Completable.
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if predicate is null
      • retryWhen

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Completable retryWhen​(@NonNull
                                                    @NonNull Function<? super Flowable<java.lang.Throwable>,​? extends org.reactivestreams.Publisher<?>> handler)
        Returns a Completable which given a Publisher and when this Completable emits an error, delivers that error through a Flowable and the Publisher should signal a value indicating a retry in response or a terminal event indicating a termination.

        Note that the inner Publisher returned by the handler function should signal either onNext, onError or onComplete in response to the received Throwable to indicate the operator should retry or terminate. If the upstream to the operator is asynchronous, signaling onNext followed by onComplete immediately may result in the sequence to be completed immediately. Similarly, if this inner Publisher signals onError or onComplete while the upstream is active, the sequence is terminated with the same signal immediately.

        The following example demonstrates how to retry an asynchronous source with a delay:

        
         Completable.timer(1, TimeUnit.SECONDS)
             .doOnSubscribe(s -> System.out.println("subscribing"))
             .doOnComplete(() -> { throw new RuntimeException(); })
             .retryWhen(errors -> {
                 AtomicInteger counter = new AtomicInteger();
                 return errors
                           .takeWhile(e -> counter.getAndIncrement() != 3)
                           .flatMap(e -> {
                               System.out.println("delay retry by " + counter.get() + " second(s)");
                               return Flowable.timer(counter.get(), TimeUnit.SECONDS);
                           });
             })
             .blockingAwait();
         
        Scheduler:
        retryWhen does not operate by default on a particular Scheduler.
        Parameters:
        handler - the Function that receives a Flowable delivering Throwables and should return a Publisher that emits items to indicate retries or emits terminal events to indicate termination.
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if handler is null
      • startWith

        @CheckReturnValue
        @NonNull
        @BackpressureSupport(FULL)
        @SchedulerSupport("none")
        public final <@NonNull T> @NonNull Flowable<T> startWith​(@NonNull
                                                                 @NonNull org.reactivestreams.Publisher<@NonNull T> other)
        Returns a Flowable which first delivers the events of the other Publisher then runs the current Completable.

        Backpressure:
        The returned Flowable honors the backpressure of the downstream consumer and expects the other Publisher to honor it as well.
        Scheduler:
        startWith does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type
        Parameters:
        other - the other Publisher to run first
        Returns:
        the new Flowable instance
        Throws:
        java.lang.NullPointerException - if other is null
      • subscribeActual

        protected abstract void subscribeActual​(@NonNull
                                                @NonNull CompletableObserver observer)
        Implement this method to handle the incoming CompletableObservers and perform the business logic in your operator.

        There is no need to call any of the plugin hooks on the current Completable instance or the CompletableObserver; all hooks and basic safeguards have been applied by subscribe(CompletableObserver) before this method gets called.

        Parameters:
        observer - the CompletableObserver instance, never null
      • subscribeWith

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final <@NonNull E extends CompletableObserver> E subscribeWith​(@NonNull E observer)
        Subscribes a given CompletableObserver (subclass) to this Completable and returns the given CompletableObserver as is.

        Usage example:

        
         Completable source = Completable.complete().delay(1, TimeUnit.SECONDS);
         CompositeDisposable composite = new CompositeDisposable();
        
         DisposableCompletableObserver ds = new DisposableCompletableObserver() {
             // ...
         };
        
         composite.add(source.subscribeWith(ds));
         
        Scheduler:
        subscribeWith does not operate by default on a particular Scheduler.
        Type Parameters:
        E - the type of the CompletableObserver to use and return
        Parameters:
        observer - the CompletableObserver (subclass) to use and return, not null
        Returns:
        the input observer
        Throws:
        java.lang.NullPointerException - if observer is null
        Since:
        2.0
      • subscribe

        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Disposable subscribe​(@NonNull
                                                   @NonNull Action onComplete,
                                                   @NonNull
                                                   @NonNull Consumer<? super java.lang.Throwable> onError,
                                                   @NonNull
                                                   @NonNull DisposableContainer container)
        Wraps the given onXXX callbacks into a Disposable CompletableObserver, adds it to the given DisposableContainer and ensures, that if the upstream terminates or this particular Disposable is disposed, the CompletableObserver is removed from the given composite.

        The CompletableObserver will be removed after the callback for the terminal event has been invoked.

        Scheduler:
        subscribe does not operate by default on a particular Scheduler.
        Parameters:
        onError - the callback for an upstream error
        onComplete - the callback for an upstream completion
        container - the DisposableContainer (such as CompositeDisposable) to add and remove the created Disposable CompletableObserver
        Returns:
        the Disposable that allows disposing the particular subscription.
        Throws:
        java.lang.NullPointerException - if onComplete, onError or container is null
        Since:
        3.1.0
      • subscribeOn

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("custom")
        public final @NonNull Completable subscribeOn​(@NonNull
                                                      @NonNull Scheduler scheduler)
        Returns a Completable which subscribes the downstream subscriber on the specified scheduler, making sure the subscription side-effects happen on that specific thread of the Scheduler.

        Scheduler:
        subscribeOn operates on a Scheduler you specify.
        Parameters:
        scheduler - the Scheduler to subscribe on
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if scheduler is null
      • takeUntil

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final @NonNull Completable takeUntil​(@NonNull
                                                    @NonNull CompletableSource other)
        Terminates the downstream if this or the other Completable terminates (wins the termination race) while disposing the connection to the losing source.

        Scheduler:
        takeUntil does not operate by default on a particular Scheduler.
        Error handling:
        If both this and the other sources signal an error, only one of the errors is signaled to the downstream and the other error is signaled to the global error handler via RxJavaPlugins.onError(Throwable).

        History: 2.1.17 - experimental

        Parameters:
        other - the other completable source to observe for the terminal signals
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if other is null
        Since:
        2.2
      • timeout

        @CheckReturnValue
        @SchedulerSupport("io.reactivex:computation")
        @NonNull
        public final @NonNull Completable timeout​(long timeout,
                                                  @NonNull
                                                  @NonNull java.util.concurrent.TimeUnit unit)
        Returns a Completable that runs this Completable and emits a TimeoutException in case this Completable doesn't complete within the given time.

        Scheduler:
        timeout signals the TimeoutException on the computation Scheduler.
        Parameters:
        timeout - the timeout value
        unit - the unit of timeout
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if unit is null
      • timeout

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("io.reactivex:computation")
        public final @NonNull Completable timeout​(long timeout,
                                                  @NonNull
                                                  @NonNull java.util.concurrent.TimeUnit unit,
                                                  @NonNull
                                                  @NonNull CompletableSource fallback)
        Returns a Completable that runs this Completable and switches to the other CompletableSource in case this Completable doesn't complete within the given time.

        Scheduler:
        timeout subscribes to the other CompletableSource on the computation Scheduler.
        Parameters:
        timeout - the timeout value
        unit - the unit of timeout
        fallback - the other CompletableSource instance to switch to in case of a timeout
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if unit or fallback is null
      • timeout

        @CheckReturnValue
        @SchedulerSupport("custom")
        @NonNull
        public final @NonNull Completable timeout​(long timeout,
                                                  @NonNull
                                                  @NonNull java.util.concurrent.TimeUnit unit,
                                                  @NonNull
                                                  @NonNull Scheduler scheduler)
        Returns a Completable that runs this Completable and emits a TimeoutException in case this Completable doesn't complete within the given time while "waiting" on the specified Scheduler.

        Scheduler:
        timeout signals the TimeoutException on the Scheduler you specify.
        Parameters:
        timeout - the timeout value
        unit - the unit of timeout
        scheduler - the Scheduler to use to wait for completion and signal TimeoutException
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if unit or scheduler is null
      • timeout

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("custom")
        public final @NonNull Completable timeout​(long timeout,
                                                  @NonNull
                                                  @NonNull java.util.concurrent.TimeUnit unit,
                                                  @NonNull
                                                  @NonNull Scheduler scheduler,
                                                  @NonNull
                                                  @NonNull CompletableSource fallback)
        Returns a Completable that runs this Completable and switches to the other CompletableSource in case this Completable doesn't complete within the given time while "waiting" on the specified Scheduler.

        Scheduler:
        timeout subscribes to the other CompletableSource on the Scheduler you specify.
        Parameters:
        timeout - the timeout value
        unit - the unit of timeout
        scheduler - the Scheduler to use to wait for completion
        fallback - the other Completable instance to switch to in case of a timeout
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if unit, scheduler or fallback is null
      • timeout0

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("custom")
        private @NonNull Completable timeout0​(long timeout,
                                              java.util.concurrent.TimeUnit unit,
                                              Scheduler scheduler,
                                              CompletableSource fallback)
        Returns a Completable that runs this Completable and optionally switches to the other CompletableSource in case this Completable doesn't complete within the given time while "waiting" on the specified Scheduler.
        Scheduler:
        You specify the Scheduler this operator runs on.
        Parameters:
        timeout - the timeout value
        unit - the unit of timeout
        scheduler - the Scheduler to use to wait for completion
        fallback - the other Completable instance to switch to in case of a timeout, if null a TimeoutException is emitted instead
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if unit, scheduler or fallback is null
      • to

        @CheckReturnValue
        @SchedulerSupport("none")
        public final <R> R to​(@NonNull
                              @NonNull CompletableConverter<? extends R> converter)
        Calls the specified CompletableConverter function during assembly time and returns its resulting value.

        This allows fluent conversion to any other type.

        Scheduler:
        to does not operate by default on a particular Scheduler.

        History: 2.1.7 - experimental

        Type Parameters:
        R - the resulting object type
        Parameters:
        converter - the CompletableConverter that receives the current Completable instance and returns a value to be the result of to()
        Returns:
        the converted value
        Throws:
        java.lang.NullPointerException - if converter is null
        Since:
        2.2
      • toFuture

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull java.util.concurrent.Future<java.lang.Void> toFuture()
        Returns a Future representing the termination of the current Completable via a null value.

        Cancelling the Future will cancel the subscription to the current Completable.

        Scheduler:
        toFuture does not operate by default on a particular Scheduler.
        Returns:
        the new Future instance
        Since:
        3.0.0
        See Also:
        ReactiveX documentation: To
      • toSingle

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final <@NonNull T> @NonNull Single<T> toSingle​(@NonNull
                                                              @NonNull Supplier<? extends @NonNull T> completionValueSupplier)
        Converts this Completable into a Single which when this Completable completes normally, calls the given Supplier and emits its returned value through onSuccess.

        Scheduler:
        toSingle does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type
        Parameters:
        completionValueSupplier - the value supplier called when this Completable completes normally
        Returns:
        the new Single instance
        Throws:
        java.lang.NullPointerException - if completionValueSupplier is null
      • toSingleDefault

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final <@NonNull T> @NonNull Single<T> toSingleDefault​(@NonNull T completionValue)
        Converts this Completable into a Single which when this Completable completes normally, emits the given value through onSuccess.

        Scheduler:
        toSingleDefault does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type
        Parameters:
        completionValue - the value to emit when this Completable completes normally
        Returns:
        the new Single instance
        Throws:
        java.lang.NullPointerException - if completionValue is null
      • unsubscribeOn

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("custom")
        public final @NonNull Completable unsubscribeOn​(@NonNull
                                                        @NonNull Scheduler scheduler)
        Returns a Completable which makes sure when an observer disposes the subscription, the dispose() method is called on the specified Scheduler.

        Scheduler:
        unsubscribeOn calls dispose() of the upstream on the Scheduler you specify.
        Parameters:
        scheduler - the target Scheduler where to execute the disposing
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if scheduler is null
      • test

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull TestObserver<java.lang.Void> test​(boolean dispose)
        Creates a TestObserver optionally in cancelled state, then subscribes it to this Completable.
        Parameters:
        dispose - if true, the TestObserver will be cancelled before subscribing to this Completable.

        Scheduler:
        test does not operate by default on a particular Scheduler.
        Returns:
        the new TestObserver instance
        Since:
        2.0
      • fromCompletionStage

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public static @NonNull Completable fromCompletionStage​(@NonNull
                                                               @NonNull java.util.concurrent.CompletionStage<?> stage)
        Signals completion (or error) when the CompletionStage terminates.

        Note that the operator takes an already instantiated, running or terminated CompletionStage. If the CompletionStage is to be created per consumer upon subscription, use defer(Supplier) around fromCompletionStage:

        
         Maybe.defer(() -> Completable.fromCompletionStage(createCompletionStage()));
         

        Canceling the flow can't cancel the execution of the CompletionStage because CompletionStage itself doesn't support cancellation. Instead, the operator detaches from the CompletionStage.

        Scheduler:
        fromCompletionStage does not operate by default on a particular Scheduler.
        Parameters:
        stage - the CompletionStage to convert to a Completable and signal onComplete or onError when the CompletionStage terminates normally or with a failure
        Returns:
        the new Completable instance
        Throws:
        java.lang.NullPointerException - if stage is null
        Since:
        3.0.0
      • toCompletionStage

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final <@Nullable T> @NonNull java.util.concurrent.CompletionStage<T> toCompletionStage​(@Nullable T defaultItem)
        Signals the given default item when the upstream completes or signals the upstream error via a CompletionStage.

        The upstream can be canceled by converting the resulting CompletionStage into CompletableFuture via CompletionStage.toCompletableFuture() and calling CompletableFuture.cancel(boolean) on it. The upstream will be also cancelled if the resulting CompletionStage is converted to and completed manually by CompletableFuture.complete(Object) or CompletableFuture.completeExceptionally(Throwable).

        CompletionStages don't have a notion of emptiness and allow nulls, therefore, one can either use a defaultItem of null or turn the flow into a sequence of Optionals and default to Optional.empty():

        
         CompletionStage<Optional<T>> stage = source.map(Optional::of).toCompletionStage(Optional.empty());
         
        Scheduler:
        toCompletionStage does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the type of the default item to signal upon completion
        Parameters:
        defaultItem - the item to signal upon completion
        Returns:
        the new CompletionStage instance
        Since:
        3.0.0