Suppose you want to insert a Completable in your Observable chain, such as for each emitted element, there is a completable that runs and blocks until it completes, what option would you choose? (here the Completable.complete()
is just to make an example)
.flatMap { Completable.complete().andThen(Observable.just(it)) }
.doOnNext { Completable.complete().blockingAwait() }
something else?
In option 2. you lose the capability of cancelling the completable because
blockingAwait()
is not managed by the observable flow.If you don't need to return the emitted element, there is also
flatMapCompletable
.If you need to execute the completable but also return the emitted element, then I would go with option 1.