https://kotlinlang.org logo
#coroutines
Title
# coroutines
s

Steffen Funke

04/14/2021, 8:40 AM
Hey all, in RxJava, we have 
doOnNext
 operators for side-effects, like printing, etc. What is the equivalent in Kotlin Flows? AFAIK, 
onEach
 consumes the flow, and would not be appropriate there. Or am I missing something?
w

wasyl

04/14/2021, 8:41 AM
onEach
doesn’t consume the flow and afaik is pretty much replacement for
doOnNext
👍 1
s

Steffen Funke

04/14/2021, 8:42 AM
Well consumes might be not the correct term, but it can alter the flow, with things like
delay(..)
, etc., while RxJava's
doOnNext
does not
e

elizarov

04/14/2021, 8:43 AM
doOnNext { Thread.sleep(100) }
alters it in a similar way. No difference.
👍 1
If you do something heavy or taking long time in either of them, you'll alter the stream. If you do something quick, then you don't
s

Steffen Funke

04/14/2021, 8:44 AM
🤔 well that makes sense
So
onEach
is the way. Thanks @elizarov, Pleasure to get an answer from the founder imself!
and also thankx @wasyl
👍 1
5 Views