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

Colton Idle

10/14/2023, 5:30 PM
Okay, bear with me. Now that StateFlows are a thing... why would you use any other Flow? Isn't everything "state"?
🚫 5
i

Ian Lake

10/14/2023, 5:54 PM
Events are not state
f

Francesc

10/14/2023, 5:56 PM
and state flows are hot
d

dbaelz

10/14/2023, 6:05 PM
What Ian said. Use flow a lot for stuff like events and one time messages
s

streetsofboston

10/14/2023, 7:30 PM
@Francesc Hot or cold flows are not defined whether they have state or not, whether they are conflated or not. StateFlows are 🔥 though 😀 Hot flows are active whether someone is listening/observing/collecting or not. Cold flows are only active while and as long someone is listening/observing/collecting.
f

Francesc

10/14/2023, 7:36 PM
right, and a
mutableStateFlow
is hot, which was my point, being hot may not be what you are after
👍 1
c

Colton Idle

10/14/2023, 9:10 PM
Thank you all! A bit of Saturday morning pondering with my
p

Patrick Steiger

10/14/2023, 10:14 PM
Consider a function that does some work and emit consecutive status updates to caller. It makes sense that ie returns a Flow built from
flow { }
Though I personally prefer to have updates sent as callbacks and result as the function return type
a

Arjan van Wieringen

10/15/2023, 6:58 AM
Events describe change, state describe “stationary” data. A state flow is a data type which has a defined state at every moment in time. How would you model a Kafka stream with Stateflow? There isn’t any defined state at every moment in time.
s

streetsofboston

10/15/2023, 2:51 PM
Kafka being an event driven architecture, a SharedFlow would fit. But stateful consumers of these events could model themselves upstream as a StateFlow (state is stored in a DB, for example).