Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RxJava doOnTerminate vs. doAfterTerminate

Tags:

rx-java

What is the value of doAfterTerminate when we already have doOnTerminate?

In the official docs here, only doOnTerminate is listed.
Why?

like image 835
ericn Avatar asked May 08 '18 02:05

ericn


People also ask

What is doFinally?

doFinally() The doFinally() operator is executed when onComplete() , onError() , or disposal happens. It is executed under the same conditions as doAfterTerminate() , plus it is also executed after the disposal.

What is the use of doOnNext?

The doOnNext operator modifies the Observable source so that it invokes an action when the onNext is called. The doOnEach operator modifies the Observable source so that it notifies an Observer for each item and establishes a callback that will be called each time an item is emitted.

What is single Rxjava?

Single is an Observable that always emit only one value or throws an error. A typical use case of Single observable would be when we make a network call in Android and receive a response. Sample Implementation: The below code always emits a Single user object. We use a Single Observable and a Single Observer.


1 Answers

You have to go to the JavaDoc for v2 to find the distinction. In doOnTerminate it says:

This differs from doAfterTerminate in that this happens before the onComplete or onError notification.

The doAfterTerminate docs don't have a similar note, although the "after" in the method name is pretty suggestive.

like image 131
T.J. Crowder Avatar answered Sep 23 '22 00:09

T.J. Crowder