Why there's no `Single#doOnTerminate` method in RxJava?

Viewed 1467

RxJava's Observable has both doOnTerminate and doAfterTerminate methods.

The difference is that doOnTerminate is called before onCompleted or onError whereas doAfterTerminate is called after. Both methods seem useful.

Single however, has only doAfterTerminate.

Is there a reason why Single does not have doOnTerminate method?

3 Answers

If you really needed the just before onComplete behavior, you can convert using Single#toObservable.

But, how I understand it: for an Observable, the term before terminated means after all items are emitted, but before onComplete. For Single, however, there is no such moment -- because emitting an item and completing is the same operation.

If there was a doOnTerminate operator, it would either mean something different (being run before the single item is emitted), or contradict the understanding of Single (emitting an item and completing is one action, so why should something be run in between) -- both of which would be kinda bad design.

Out of curiosity: what was your original case, that you couldn't make the call in doAfterTerminate or before launching the Single?

Related