Chain Completable into Observable flow

Adi B picture Adi B · Nov 28, 2017 · Viewed 7.9k times · Source

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)

  1. .flatMap { Completable.complete().andThen(Observable.just(it)) }

  2. .doOnNext { Completable.complete().blockingAwait() }

  3. something else?

Answer

Ankit Kumar picture Ankit Kumar · Dec 14, 2017
.flatMapCompletable { Completable.complete().andThen(Observable.just(it)) } // If you don't want it to return
.flatMap { Completable.complete().andThen(Observable.just(it)) } //Can be used if you want it to return Observable