https://kotlinlang.org logo
#flow
Title
# flow
k

Kevin Worth

09/29/2023, 3:22 PM
I’m struggling a bit to understand
onSubscribe
of
SharedFlow
as it relates to
onStart
of
Flow
. First question would be, is there a scenario where
onStart
gets called only once and then
onSubscribe
is called for each new subscriber and/or re-subscriber? See 🧵 for more details. Any help would be appreciated.
In my attempts to put together a contrived example - which has not been easy, so perhaps I’m doing it poorly/incorrectly - I seem to always see both
onSubscribe
and
onStart
get called. The wording led me to expect that
onStart
would only get called once, when the first subscriber started collecting.
Second question would be, am I correct in understanding that
onSubscribe
can get called without
onStart
getting called (yet)? If so, what does that look like? How do I write some code where I only subscribe and don’t call a collecting method?
2 Views