Completable empty = (completableSubscriber -> { The Completable API follows the concepts of the Reactive-Streams. Create, Lift and Transform. The Completable class has three additional standard helper interfaces, now becoming common with all RxJava. Creating a Single. Completable. Creating a Completable. Maybe. Creating a Maybe. RxCocoa traits. Driver. Why is it named Driver; Practical usage example.

Author: Samur Tojajas
Country: Saudi Arabia
Language: English (Spanish)
Genre: Spiritual
Published (Last): 1 October 2016
Pages: 274
PDF File Size: 16.5 Mb
ePub File Size: 17.33 Mb
ISBN: 472-6-31097-922-7
Downloads: 75070
Price: Free* [*Free Regsitration Required]
Uploader: Akinoshura

Returns a Completable instance that calls the given onSubscribe callback with the disposable that child subscribers receive on subscription.

Clearer RxJava intentions with Single and Completable

In this two part series, I’m first going to introduce the usage of this class and its relation to the existing Observable and Single classes, then I’ll explain the internals and development practices of Completable operators.

Sign up or log in Sign up using Google. Completable mandates side effects when subscribed to and it is its main purpose indeed.

Dealing with exceptions Completable. Note that as with the Observable protocol, onError and onComplete are mutually exclusive events.

Completable (RxJava Javadoc )

When onError or onCompleted is called, the formerly received Subscription should be considered already unsubscribed. The returned Completable honors the backpressure of the downstream consumer and expects the other Publisher to honor it as well. The Completable class implements the CompletableSource base interface and the default consumer type it interacts with is the CompletableObserver via the subscribe CompletableObserver method.

The rules, however, allow for a much simpler version: Subscribes to and awaits the termination of this Completable instance in a blocking manner and rethrows any exception emitted. If we really want to make sure the Subscription the child receives is actually unsubscribed, we have to add a level of indirection via a MultipleAssignmentSubscription: There is no need to call any of the plugin complwtable on the current Completable instance or the CompletableObserver ; all hooks and basic safeguards have been applied by subscribe CompletableObserver before this method gets called.


Regardless, let’s see a completab,e examples. For the case of empty, it means we have to create some instance of the Subscription interface: We achieve this by manually unsubscribe our BooleanSubscription 3 and calling the onCompleted method. This is an interesting optimization in the Completable and in Reactive-Streams world and it does technically work: Completable contains some deferred computation with side effects and only compldtable about the success or failure of such computation.

Returns a Completable instance that completes immediately when subscribed to. It contains a mandatory onSubscribe call with a non-null argument followed by, optionally, either an onError with a non-null Throwable or an onCompleted. The second reason for the show order is that unsubscribing a Worker may cause unwanted interruptions down the line of onCompleted. Hides the identity of this Completable and its Disposable. This may look a bit complicated for such a simple operator.

In both completablf we atomically swap in the terminated array and loop through the previous completablf while emitting the completsble terminal event.

The following example demonstrates how to retry an asynchronous source with a delay: Note that as the Experimental tag indicates, method names and their availability may cojpletable at any time before or after 1.

This complicates the error management and tracking of completed students slightly: Implement this method to handle the incoming CompletableObserver s and perform the business logic in your operator.

Description copied from interface: As within Reactive-Streams, the methods can’t throw any checked exceptions or unchecked exceptions other than NullPointerException. Returns a Completable that runs this Completable and switches to the other Completable in case this Completable doesn’t complete within the given time.

Returns a Completable instance that repeats when the Publisher returned by the handler completale an item or completes when this Publisher emits a completed event. It accepts Action objects. This is perfectly fine and you can use it as is. Never miss a story from AndroidPubwhen you sign up for Medium.


In the scheduled task, we unsubscribe the worker after calling onCompleted at which point it is clear the worker is not unsubscribed.

The add and remove methods have the usual and familiar implementations that allows tracking the subscribed child CompletableSubscriber s.

We will see example how to implement this. Unsurprisingly, many of them match their counterpart in Observablehowever, a lot of them is missing because they don’t make sense in a valueless stream. CompletableObserver can decide to not subscribe to its upstream after all.

Meaning, we just want the creeate event. Exceptions thrown at this time will be delivered to RxJavaPlugins only. Returns a Completable instance that runs the given Action for each subscriber and emits either an unchecked exception or simply completes.

It features the usual onCompleted and onError but instead of extending Subscription and having an add method like rx. 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.

Depending on the need for these, they can be added later on. We want to change some properties on the MyData object and then send it to the server to update in its database.

Clearer RxJava intentions with Single and Completable

The State class will hold onto the terminal indicator and the optional Throwable instance along with the array of known child CompletableSubscriber s: Empty delayed Let’s assume we want to emit the onCompleted event after some delay. Without it, there wouldn’t be any way of cancelling such subscriptions. Nulls creatd references to the upstream producer and downstream CompletableObserver if the sequence is terminated or downstream calls dispose. You specify which Scheduler this operator will use.