Skip to content
Advertisement

What is the purpose of doOnNext(…) in RxJava

When should we use doOnNext() from Observable instead of just onNext()?

Advertisement

Answer

doOnNext is for side-effects: you want to react (eg. log) to item emissions in an intermediate step of your stream, for example before the stream is filtered, for transverse behavior like logging, but you still want the value to propagate down the stream.

onNext is more final, it consumes the value.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement