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

asad.awadia

08/30/2019, 9:35 PM
What is the use case for flows?
z

zak.taccardi

08/30/2019, 9:35 PM
multiple values over time
a

asad.awadia

08/30/2019, 9:35 PM
For what use case tho?
z

zak.taccardi

08/30/2019, 9:36 PM
are you familiar with RxJava?
or LiveData<T>
a

asad.awadia

08/30/2019, 9:36 PM
Yes
z

zak.taccardi

08/30/2019, 9:36 PM
that’s the use case
a

asad.awadia

08/30/2019, 9:36 PM
Thats not a use case
A use case is like when a user is typing then you do foobar
z

zak.taccardi

08/30/2019, 9:36 PM
okay
for a ViewModel to expose a stream of states
a

asad.awadia

08/30/2019, 9:37 PM
Preferably examples on server side than UI side
z

zak.taccardi

08/30/2019, 9:37 PM
it would be represented as
Flow<State>
a

asad.awadia

08/30/2019, 9:37 PM
Basics events?
z

zak.taccardi

08/30/2019, 9:37 PM
I don’t do server side dev so I couldn’t tell you
a

asad.awadia

08/30/2019, 9:37 PM
Basically #
z

zak.taccardi

08/30/2019, 9:37 PM
yes, events would qualify
in any place you would set a listener to receive callbacks for multiple values over time,
Flow<T>
makes sense
for a single value,
suspend () -> T
should be preferred
a

asad.awadia

08/30/2019, 9:38 PM
Hmm i guess that kinda makes sense
Wonder how to use it backend side
z

zak.taccardi

08/30/2019, 9:39 PM
a socket connection?
(maybe)
a

asad.awadia

08/30/2019, 9:39 PM
How?
Lol
z

zak.taccardi

08/30/2019, 9:39 PM
subscribing to a
Flow<T>
would create a socket connection containing events of type
T
g

gildor

08/31/2019, 3:22 AM
Every stream of events can be represented as Flow: Server requests, socket connection, database updates, periodical events etc Essentially everything where you use callbacks that can be called multiple times. For example check how Spring uses Reactor (which is also reactive library), you can represent whole web service as chain of events where source is request that converted to response event
5 Views