0

I have a RxJava's chain that looks like this:

Completable.complete()
    .andThen(fetchData())
    .andThen(fetchAnotherData())
    .andThen(...)
    .doOnSubscribe {
        /* some action */
    }

The problem is that code in doOnSubscribe callback called after last andThen(). But I want it to be called before fetching any data. How do I achieve it?

1 Answers1

1

Try defer the subscription of fetchData() Completable

   Completable.complete()
            .andThen(Completable.defer { fetchData() })
            .andThen(Completable.defer { fetchAnotherData() })
            .doOnSubscribe { /* some action */ }
Sarath Kn
  • 2,680
  • 19
  • 24
  • Have a look in to this answer as well https://stackoverflow.com/questions/48624863/rxjava-completable-andthen-is-not-executing-serially/48624894?noredirect=1#comment99285405_48624894 – Sarath Kn Feb 26 '20 at 06:16